思路:SG打表
代码:
#include<queue> #include<cstring> #include<set> #include<map> #include<stack> #include<cmath> #include<vector> #include<cstdio> #include<iostream> #include<algorithm> #define eps 1e-9 typedef long long ll; const int maxn = 1e3 + 10; const int seed = 131; const ll MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; using namespace std; int fib[50]; int s[maxn], sg[maxn]; void getSG(){ sg[0] = 0; for(int i = 1; i <= 1000; i++){ memset(s, 0, sizeof(s)); for(int j = 1; fib[j] <= i; j++){ s[sg[i - fib[j]]] = 1; } for(int j = 0; j <= i; j++){ if(!s[j]){ sg[i] = j; break; } } } } void FIB(){ fib[1] = 1, fib[2] = 2; for(int i = 3; i <= 30; i++) fib[i] = fib[i - 1] + fib[i - 2]; } int main(){ int n, m, p; FIB(); getSG(); while(scanf("%d%d%d", &n, &m ,&p) && n + m + p){ if(sg[n] ^ sg[m] ^ sg[p]) printf("Fibo "); else printf("Nacci "); } return 0; }