本文主要是介绍hdu1848,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
sg函数#include <iostream>
#include <string.h>using namespace std;#define MAXN 1000 + 10int f[MAXN];
int sg[MAXN];
bool vis[MAXN];void getsg()
{sg[0] = 0;for (int i = 1; i <= 1000; i++){memset(vis, false, sizeof(vis));for (int j = 1; f[j] <= i; j++){vis[sg[i - f[j]]] = true;}for (int j = 0; j <= 1000; j++){if (!vis[j]){sg[i] = j;break;}}}
}void input()
{int n, m, p;f[0] = 1;f[1] = 1;for (int i = 2; i <= 16; i++){f[i] = f[i - 1] + f[i - 2];}getsg();while (cin >> n >> m >> p, n + m + p){cout << (sg[n] ^ sg[m] ^ sg[p] ? "Fibo" : "Nacci") << endl;}
}int main()
{input();return 0;
}
这篇关于hdu1848的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!