HDU 1848(模拟sg)

http://acm.hdu.edu.cn/showproblem.php?pid=1848

模拟sg

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n,m,p;
int f[maxn],vis[maxn],sg[maxn];
void Init(){
f[1] = 1;
f[2] = 2;
for(int i = 3; i <= 1000; i++)
f[i] = f[i - 1] + f[i - 2];
sg[0] = 0;
for(int i = 1; i <= 1000; i++){
memset(vis,0, sizeof(vis));
for(int j = 1; f[j] <= i; j++)
vis[sg[i - f[j]]] = 1;
for(int j = 0; j <= 1000;j++){
if(!vis[j]){
sg[i] = j;
break;
}
}
}
}
int main(){
//freopen("in","r",stdin);
ios::sync_with_stdio(0);
Init();
while(cin >> n >> m >> p){
if(!n && !m && !p) break;
if(sg[n] ^ sg[m] ^ sg[p])
cout << "Fibo" << endl;
else cout << "Nacci" << endl;
}
return 0;
}
原文地址:https://www.cnblogs.com/xcfxcf/p/12548168.html