//smp.c
#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h>
#include <sys/sysinfo.h> //get_nprocs()
#include <pthread.h>
#define MAX_VALUE 1000000
inline int set_cpu(int i)
{
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(i,&mask);
if(-1 == sched_setaffinity(0,sizeof(cpu_set_t),&mask))
{
return -1;
}
return 0;
}
void* pth_add(void* x)
{
in...
阅读全文
nyoj 886 :点击打开链接
威佐夫博弈, 在判断的基础上加上输出第一步走法。
输出第一步走法实际就是将石子数减小到必败态,计算出来的k和k+s就是一组必败态,只要判断a到k,和b到k+s的距离是否相等来就能判断是否能从两堆中取相同数目的石子达到必败态。
接下来考虑从某一堆中取石子,
a[i] = [i * (1 + sqrt(5)) / 2],b[i] = a[i] +i
通过枚举i,知道i以后可以算出a[i] 和b[i]。然后进行判断即可。
#include <stdio.h&g...
阅读全文
nyoj 888:点击打开链接
反nim 详细看这里:点击打开链接
#include <stdio.h>
int main (void)
{
int n, t;
scanf("%d", &t);
while(t --)
{
scanf("%d", &n);
int a, count = 0, sum = 0;
int i;
for(i = 0; i < n; i++)
{
scanf("%d", &a);
sum ^= a;
if(a > 1)
count++;
}
...
阅读全文
tyvj 1038:
同一段序列,对序列询问很多次,用线段树。
第一次写线段树……
先贴上大神给的模板:
// xian duan shu
#include <stdio.h>
#define N 200001
#define max(a,b) a>b?a:b
struct node
{
int l,r;
int maxx;
};
node line[N*3];
int val[N];
void build(int l,int r,int s)
{
line[s].l = l;
line[s].r = r;
if (l == r)
{
line[s].maxx = val[l];
return;
}
int mid = (l+r)>>1;
buil...
阅读全文
tyvj 1228:
字典树。
#include <stdio.h>
#include <string.h>
struct node
{
char *s;
bool f;//单词结束的标志
node *next[26];
node()
{
int i;
for(i = 0; i < 26; i++)
next[i] = NULL;
f = 0;
}
};
void build(node *head, char str[])
{
node *temp = head;
int i, len = strlen(str), j;
for(i = 0; i < len; i ++)
{
int t = str[i] - 'a';
if(temp->next[t] == NUL...
阅读全文
tyvj 1297:
比较简单的线段树。
#include <stdio.h>
int a[50010];
struct node
{
int l, r, min, max;
};
node tree[50010 * 3];
void build(int ll, int rr, int s)
{
tree[s].l = ll;
tree[s].r = rr;
while(ll == rr)
{
tree[s].min = tree[s].max = a[ll];
return ;
}
int mid = (ll + rr) / 2;
build(ll, mid, s * 2);
build(mid + 1, rr, s * 2 + 1);
tree[s].min = tree[s * 2].min < tree[...
阅读全文
tyvj 1567:
博弈,题目给的数据是不超过1000位,所以这题应该找规律求解。
我是将30以内的sg值值求出来,然后规律就很容易看出来啦。
求sg值:
#include <stdio.h>
#include <string.h>
int sg[100][100];
int getsg(int x, int y)
{
int i;
if(sg[x][y] != -1)
return sg[x][y];
bool vis[100];
memset(vis, 0, sizeof(vis));
for(i = 1; i < x; i++)
vis[getsg(x - i, i)] = 1;
for(i = 1; i &l...
阅读全文
tyvj 1968:
我的方法,将SG值打出来,然后就可以看到规律。
具体的想法可以看------>点击打开链接
#include <stdio.h>
#include <string.h>
int sg[15][35];
int day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int getsg(int x, int y)
{
if(sg[x][y] != -1)
return sg[x][y];
bool vis[100];
memset(vis, 0, sizeof(vis));
if(x < 10 || x == 10 && y <= 4)
...
阅读全文
Description
Your task is to calculate the sum of some integers.
Input
Input contains multiple test cases, and one case one line.
Each case starts with an integer N( 0 < N<=500 ),
and then N integers follow in the same line.
Output
For each test case you should output the sum of N integers in one line,
and with one line of output for each line in input.
Sample Input
4 1 2 ...
阅读全文