题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1847
1 3
Kiki Cici
PS:
不懂SG的请猛戳:
1、http://www.cnitblog.com/weiweibbs/articles/42735.html
2、http://www.cnblogs.com/frog112111/p/3199780.html
代码如下:
#include <cstdio> #include <cstring> int x[12],SG[1056]; int vis[1056]; void init() { for(int i = 0; i < 11 ; i++) x[i] = 1<<i; SG[0] = 0; for(int i = 1; i < 1002; i++)//get Sprague-Grundy value; { memset(vis,0,sizeof(vis)); for(int j = 0; x[j] <= i; j++) { vis[SG[i-x[j]]] = 1; } for(int j = 0; ; j++)//求mes{}中未出现的最小的非负整数 { if(!vis[j]) { SG[i] = j; break; } } } } int main () { int n; init(); while (~scanf("%d",&n)) { if(SG[n]) puts("Kiki"); else puts("Cici"); } return 0; }
#include<cstdio> int main() { int n; while(~scanf("%d",&n)) { if(n%3) printf("Kiki\n"); else printf("Cici\n"); } return 0; }
HDU 1847 Good Luck in CET-4 Everybody!(SG的简单运用)
原文地址:http://blog.csdn.net/u012860063/article/details/43491017