http://codeforces.com/contest/604/problem/E
题意:有两个人做游戏,游戏规则如下:
有n堆石子,每次可以对一堆石子进行操作,如果当前石子是偶数,那么可以选择将这2*x个石子分成k堆石子数为x的石子堆,还有一种没有前提的操作是取走当前堆的一个石子,问先手赢还是后手赢,先手和后手都足够聪明的情况下。
思路:博弈论。。不会做。。第一次接触sg函数。。转载一篇题解:
http://m.blog.csdn.net/blog/qq_24451605/50154973
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
/* *********************************************** Author :111qqz Created Time :2015年12月22日 星期二 14时29分05秒 File Name :code/cf/#334/E.cpp ************************************************ */ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <cmath> #include <cstdlib> #include <ctime> #define fst first #define sec second #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define ms(a,x) memset(a,x,sizeof(a)) typedef long long LL; #define pi pair < int ,int > #define MP make_pair using namespace std; const double eps = 1E-8; const int dx4[4]={1,0,0,-1}; const int dy4[4]={0,-1,1,0}; const int inf = 0x3f3f3f3f; int n,k,res; int pre[5]={0,1,0,1,2}; int grundy( int a) { if (k%2==0) { if (a==1) return 1; if (a==2) return 2; return (a%2)^1; } else { if (a<5) return pre[a]; if (a%2==1) return 0; return (grundy(a/2)==1?2:1); } } int main() { #ifndef ONLINE_JUDGE freopen("code/in.txt","r",stdin); #endif cin>>n>>k; for ( int i = 0 ; i < n; i++) { int x; cin>>x; res ^= grundy(x); } if (res!=0) { puts("Kevin"); } else { puts("Nicky"); } #ifndef ONLINE_JUDGE fclose(stdin); #endif return 0; } |
说点什么
您将是第一位评论人!