Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12753 Accepted Submission(s): 5563
#include <iostream> #include<string.h> #include<cstdio> using namespace std; const int MAXN = 1005; int f[MAXN]; int s[MAXN]; int sg[MAXN]; void getSG(int n) { int i,j; for(i=1;i<=n;i++) { memset(s,0,sizeof(s)); for(j=0;f[j]<=i&&j<=20;j++) s[sg[i-f[j]]]=1; for(j=0;;j++) { if(!s[j]) { sg[i]=j; break; } } } } int main() { f[1]=1,f[0]=1; for(int i=2;i<=16;i++) f[i]=f[i-1]+f[i-2]; getSG(1000); int m,n,p; while(scanf("%d%d%d",&m,&n,&p),m||n||p) { if(sg[m]^sg[n]^sg[p]) cout << "Fibo" << endl; else cout << "Nacci" << endl; } return 0; }
原文:https://www.cnblogs.com/wjc2021/p/10667992.html