IT民工
加油!
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

const int MAXN = 1005;
int fib[MAXN], e[MAXN], h[20];

void calcFib()
{
    int i;
    fib[1] = 1, fib[2] = 2;
    for(i = 3; i <= 16; i ++)
    {
        fib[i] = fib[i - 1] + fib[i - 2];
    }
}

/*求SG值*/
void calcE()
{
    int i, j, k;
    e[0] = 0, e[1] = 1;
    for(i = 2; i <= 1000; i ++)
    {
        memset(h, 0, sizeof h);
        for(j = 1; fib[j] <= i; j ++)
        {
            h[e[i - fib[j]]] = 1;
        }
        for(j = 0; j <= 15; j ++)
        {
            if(h[j] == 0) //当j为必败态
            {
                e[i] = j;
                break;
            }
        }
    }
}

int main()
{
    int m, n, p;
    calcFib();
    calcE();
    while(scanf("%d%d%d", &m, &n, &p), m || n || p)
    {
        puts(((e[m] ^ e[n] ^ e[p]) == 0) ? "Nacci" : "Fibo"); //异或为0,先手必败
    }
    return 0;
}

 

posted on 2012-10-20 11:11  找回失去的  阅读(148)  评论(0编辑  收藏  举报