1 1 1 1 4 1 0 0 0
Fibo Nacci
博弈,SG函数的运用!!!
AC代码如下:
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int fb[1001]; int sg[1001]; int next[1001]; int n; void getsg() { int i,j; memset(sg,0,sizeof sg); for(i=1;i<=1000;i++) { memset(next,0,sizeof next); for(j=0;j<n;j++) { if(i<fb[j]) break; next[sg[i-fb[j]]]=1; } for(j=0;j<=1000;j++) { if(!next[j]) {sg[i]=j;break;} } } } void getfb() { int i; fb[0]=1;fb[1]=2; for(i=2;;i++) { fb[i]=fb[i-1]+fb[i-2]; if(fb[i]>1000) break; } n=i; } int main() { getfb(); getsg(); int a,b,c; while(~scanf("%d%d%d",&a,&b,&c)&&(a||b||c)) { if((sg[a]^sg[b]^sg[c])==0) printf("Nacci\n"); else printf("Fibo\n"); } return 0; }
HDU 1848 Fibonacci again and again,布布扣,bubuko.com
HDU 1848 Fibonacci again and again
原文地址:http://blog.csdn.net/hanhai768/article/details/38146119