标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7266 Accepted Submission(s):
3019
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define N 1005 int S[1000]; int cnt; void getfab() { S[1]=1; S[2]=2; cnt=3; while(S[cnt-1]<=1000) { S[cnt]=S[cnt-1]+S[cnt-2]; cnt++; } } int sg[1005],flag[1005]; void Sg(int *S,int len) { int i,j; memset(sg,0,sizeof(sg)); for(i=1;i<=N;i++) { memset(flag,0,sizeof(flag)); for(j=1;j<len;j++) if(i-S[j]>=0) flag[sg[i-S[j]]]=1; for(j=0;j<=N;j++) if(!flag[j]) break; sg[i]=j; } } int main() { int m,n,p; getfab(); Sg(S,cnt); while(scanf("%d%d%d",&m,&n,&p)!=EOF&&(m||n||p)) { int res=sg[m]^sg[n]^sg[p]; if(res) printf("Fibo\n"); else printf("Nacci\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/jasonlixuetao/p/5702226.html