标签:sg函数 斐波那契 const put puts href ref type 不为
可取状态只能是斐波那契数,求出SG函数
然后判断三个数sg函数异或和不为0先手必胜
#include <cstdio>
#include <cctype>
#define rr register
using namespace std;
const int p[15]={1,2,3,5,8,13,21,34,55,89,144,233,377,610,987};
const int N=1011; int sg[N],v[N];
inline signed iut(){
rr int ans=0; rr char c=getchar();
while (!isdigit(c)) c=getchar();
while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
return ans;
}
signed main(){
for (rr int i=1;i<N;++i){
for (rr int j=0;j<15&&p[j]<=i;++j)
v[sg[i-p[j]]]=1;
for (;v[sg[i]];++sg[i]);
for (rr int j=0;j<15&&p[j]<=i;++j)
v[sg[i-p[j]]]=0;
}
while (1){
rr int n=iut(),m=iut(),k=iut();
if (!n&&!m&&!k) break;
if (sg[n]^sg[m]^sg[k]) puts("Fibo");
else puts("Nacci");
}
return 0;
}
#SG函数#HDU 1848 Fibonacci again and again
标签:sg函数 斐波那契 const put puts href ref type 不为
原文地址:https://www.cnblogs.com/Spare-No-Effort/p/14619215.html