Fibonacci again and again (game + SG play table)

Problem Description
Any college student should be familiar with Fibonacci numbers, which are defined like this:
F(1)=1;
F(2)=2;
F(n)=F(n-1) +F(n-2)(n>=3);
So, 1,2,3,5,8,13...is the Fibonacci sequence.
There are many related questions on HDOJ, such as 1005 Fibonacci again, which was once a question in Zhejiang Province.
Today, another topic about Fibonacci appeared. It is a small game, which is defined as follows:
1. This is a two-player game;
2. There are 3 piles of stones, and the numbers are m, n, and p respectively;
3. Two People take turns to walk;
4. Each step can choose any pile of stones, and then take f;
5. f can only be an element in the Fibonacci sequence (that is, only 1, 2, 3, 5, 8… etc.);
6. The person who takes all the stones first is the winner;

assuming both sides use the optimal strategy, please judge whether the first player will win or the second player will win.
 

Input
The input data contains multiple test cases, each test case occupies a row, and contains 3 integers m,n,p (1<=m,n,p<=1000).
m=n=p=0 means the end of the input.
 

Output
If the first player wins, output "Fibo", otherwise, output "Nacci", one line per instance.
 

Sample Input
 
  
1 1 11 4 10 0 0
 

Sample Output
 
  
FiboNacci

SG play meter

#include <stdio.h>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 1000;
int sg[maxn] , Hash[maxn] , F[maxn];
void getsg(int n)
{
	memset(sg , 0 ,sizeof(sg));
	for(int i = 1 ; i <= n ; i++)
	{
		memset(Hash , 0 , sizeof(Hash));
		for(int j = 1 ; F[j] <= i ; j++)
		{
			Hash[sg[i-F[j]]] = 1;
		}
		for(int j = 0 ; j <= n ; j++)
		{
			if(Hash[j] == 0)
			{
				sg[i] = j;
				break;
			}
		}
	
	}
//	for(int i = 0 ; i <= n ; i++)
//	{
//		cout << i << ":" << sg[i] << endl;
//	}
}
intmain()
{
	int m , n , p;
	while(~scanf("%d %d %d" , &m , &n , &p)&&(m+n+p))
	{
		F[0] = F[1] = 1;
		for(int i = 2 ; i < 20 ; i++)
		{
			F[i] = F[i-1] +F[i-2];
		}
		getsg(1000);
		if(	sg[m] ^sg[n]^sg[p])
		{
			printf("Fibo\n");
		}
		else
		{
			printf("Nacci\n");
		}
	}
	return 0;
 }

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326747046&siteId=291194637