hdu 1847 Good Luck in CET-4 Everybody!(简单博弈SG)
#include<stdio.h> #include<string.h> #define N 1010 int hash[N]; int sg[N]; void GetSG() { int i,j; for(i=1;i<N;i++) { memset(hash,0,sizeof(hash)); for(j=1;j<=i;j*=2) { hash[sg[i-j]]=1; } for(j=0;j<N;j++) { if(!hash[j]) { sg[i]=j; break; } } } /*for(i=1;i<50;i++) printf("%d ",sg[i]);*/ } int main() { int n; GetSG(); while(scanf("%d",&n)!=EOF) { if(sg[n])printf("Kiki\n"); else printf("Cici\n"); } return 0; }