1 1 1 1 4 1 0 0 0
Fibo Nacci
代码:
#include <iostream> #include <string.h> using namespace std; const int N=1002; int f[N],sg[N],hash[N]; void getf() { f[1]=1; f[2]=2; for(int i=3;i<=1000;i++) { f[i]=f[i-1]+f[i-2]; if(f[i]>1000) break; } } void getSG(int n) { int i,j; memset(sg,0,sizeof(sg)); for(i=1;i<=n;i++) { memset(hash,0,sizeof(hash)); for(j=1;f[j]<=i;j++) hash[sg[i-f[j]]]=1; for(j=0;j<=n;j++) //求mes{}中未出现的最小的非负整数 { if(hash[j]==0) { sg[i]=j; break; } } } } int main() { int m,n,p; getf(); getSG(1000); while(cin>>m>>n>>p&&(m||n||p)) { int sum=0; sum^=sg[m]^sg[n]^sg[p]; if(sum==0) cout<<"Nacci"<<endl; else cout<<"Fibo"<<endl; } return 0; }
[ACM] hdu 1848 Fibonacci again and again(Nim博弈 SG函数),布布扣,bubuko.com
[ACM] hdu 1848 Fibonacci again and again(Nim博弈 SG函数)
原文:http://blog.csdn.net/sr_19930829/article/details/23420445