link:
http://acm.hdu.edu.cn/showproblem.php?pid=1848
Meaning of the questions:
Any of a Students Fibonacci series (Fibonacci numbers) will not be familiar with, it is defined as:
F. (. 1) =. 1;
F. (2) = 2;
F. (N-) = F. (. 1-n-) + F (n-2) ( n> = 3);
therefore, 1,2,3,5,8,13 ...... is Fibonacci series.
There are a lot of related topics on HDOJ, such as the 1005 Fibonacci again is ever tournament title of Zhejiang Province.
Today, another topic about Fibonacci appeared, it is a game, is defined as follows:
1, this is a game for two;
2, a total of three heap of stones, namely the number of m, n, p a;
3, two people take turns walking;
4, every step you can select any pile of gravel, then removed the f;
5, f only Fibonacci series of elements (ie you can only get 1,2,3,5, number 8 ... etc.);
6, the first light-trapping all artificial stones winner;
Assuming that both parties are using the optimal strategy, please just get to determine who will win or who will win the flip.
Ideas:
Obtaining SG function determines
Code:
// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string.h>
#include<set>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MOD = 1e9;
const int MAXN = 1e3+10;
int Vis[MAXN], Sg[MAXN];
int F[MAXN];
int n, m, p;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
F[1] = 1, F[2] = 2;
for (int i = 3;F[i-1] <= 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++) if (Vis[j] == 0)
{
Sg[i] = j;
break;
}
}
while(~scanf("%d%d%d", &n, &m, &p) && n)
{
if ((Sg[n]^Sg[m]^Sg[p]) == 0)
puts("Nacci");
else
puts("Fibo");
}
return 0;
}