题目链接:点击打开链接
题目叙述:变形的nim,每次拿都为fibonacci数(但是从1,2,3,5,开始)一共三堆;
根据理论:2. If G = G1 + G2 and v = (v1; v2) 2 V1 £ V2, then g(v) is the bitwise XOR, or nim-sum,of the binary representations of g(v1) and g(v2).
所以求出每堆的sg函数,然后再异或。因为样本不大所以可以用记忆化搜索,否则只能大表看规律
#include<cstdlib>
#include<cstdio>
#include<iostream>
using namespace std;
int fi[15],sg[1002];
int sf(int n)
{
int i,tmp;
int hash[20]={0};
for(i=0;i<15;i++)
{
tmp=n-fi[i];
if(tmp<0)
break;
if(sg[tmp]==-1)
sg[tmp]=sf(tmp);
hash[sg[tmp]]=1;
}
for(i=0;i<20;i++)
if(hash[i]==0)return i;
}
int main()
{ fi[0]=1;fi[1]=2;
for(int i=2;i<15;i++)
fi[i]=fi[i-1]+fi[i-2];
int m,n,p;
while(scanf("%d%d%d",&m,&n,&p)!=EOF&&(m||n||p))
{
memset(sg,-1,sizeof(sg));
int ans=sf(m)^sf(n)^sf(p);
if(ans==0)
printf("Nacci\n");
else
printf("Fibo\n");
}
return 0;
}