hdu 1848 Fibonacci again and again

简介:

这是尼姆博弈的变型;
还是博弈,但是这次要用Sg函数最后异或等于0后手赢
反之,先手赢

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int f[100]={1,2,3,5};
int e[1005]={0,1,2,3};
int b[16];
void Init()
{
    for(int i=3; f[i-1]<=1000; i++)
    f[i] = f[i-1] + f[i-2];
    for(int i=4; i<1005; i++)
    {
        e[i]=i;
        memset(b,0,sizeof(b));
        for(int j=0; f[j]<=i; j++)
        b[e[i-f[j]]]=1;
        for(int j=0; j<15; j++)
        if(b[j] == 0)
        {
            e[i]=j;
            break;
        }
    }
}
int main()
{
    Init();
    int n,p,k;
    while(cin>>n>>p>>k,n,p,k)
    {
        if(!(e[n]^e[p]^e[k]))
        puts("Nacci");
        else
        puts("Fibo");
    }
    return 0;
}
目录
相关文章
HDOJ(HDU) 2212 DFS(阶乘相关、)
HDOJ(HDU) 2212 DFS(阶乘相关、)
97 0
|
机器学习/深度学习
POJ 1775 (ZOJ 2358) Sum of Factorials
POJ 1775 (ZOJ 2358) Sum of Factorials
146 0
|
Java
HDU 1021 Fibonacci Again
Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 58267    Accepted Submission(...
904 0
|
人工智能 机器学习/深度学习
POJ 1775 (ZOJ 2358) Sum of Factorials
Description John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions t...
1146 0