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

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2015年12月22日 星期二 14时29分05秒
 4File Name :code/cf/#334/E.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33int n,k,res;
34int pre[5]={0,1,0,1,2};
35
36int grundy( int a)
37{
38    if (k%2==0)
39    {
40	if (a==1) return 1;
41	if (a==2) return 2;
42	return (a%2)^1;
43    }
44    else
45    {
46	if (a<5) return pre[a];
47	if (a%2==1) return 0;
48	return (grundy(a/2)==1?2:1);
49    }
50}
51int main()
52{
53	#ifndef  ONLINE_JUDGE 
54	freopen("code/in.txt","r",stdin);
55  #endif
56
57	cin>>n>>k;
58	for ( int i = 0 ; i < n; i++)
59	{
60	    int x;
61	    cin>>x;
62	    res ^= grundy(x);
63	}
64	if (res!=0)
65	{
66	    puts("Kevin");
67	}
68	else
69	{
70	    puts("Nicky");
71	}
72
73  #ifndef ONLINE_JUDGE  
74  fclose(stdin);
75  #endif
76    return 0;
77}