codeforces #334 div 2 E. Lieges of Legendre

http://codeforces.com/contest/604/problem/E 题意:有两个人做游戏,游戏规则如下: 有n堆石子,每次可以对一堆石子进行操作,如果当前石子是偶数,那么可以选择将这2*x个石子分成k堆石子数为x的石子堆,还有一种没有前提的操作是取走当前堆的一个石子,问先手赢还是后手赢,先手和后手都足够聪明的情况下。 思路:博弈论。。不会做。。第一次接触sg函数。。转载一篇题解: http://m.blog.csdn.net/blog/qq_24451605/50154973

/* ***********************************************
Author :111qqz
Created Time :2015年12月22日 星期二 14时29分05秒
File Name :code/cf/#334/E.cpp
************************************************ */
 1#include <cstdio>
 2#include <cstring>
 3#include <iostream>
 4#include <algorithm>
 5#include <vector>
 6#include <queue>
 7#include <set>
 8#include <map>
 9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6int n,k,res;
7int pre[5]={0,1,0,1,2};
 1int grundy( int a)
 2{
 3    if (k%2==0)
 4    {
 5	if (a==1) return 1;
 6	if (a==2) return 2;
 7	return (a%2)^1;
 8    }
 9    else
10    {
11	if (a<5) return pre[a];
12	if (a%2==1) return 0;
13	return (grundy(a/2)==1?2:1);
14    }
15}
16int main()
17{
18	#ifndef  ONLINE_JUDGE 
19	freopen("code/in.txt","r",stdin);
20  #endif
 1	cin>>n>>k;
 2	for ( int i = 0 ; i < n; i++)
 3	{
 4	    int x;
 5	    cin>>x;
 6	    res ^= grundy(x);
 7	}
 8	if (res!=0)
 9	{
10	    puts("Kevin");
11	}
12	else
13	{
14	    puts("Nicky");
15	}
1  #ifndef ONLINE_JUDGE  
2  fclose(stdin);
3  #endif
4    return 0;
5}