hdu1848 Fibonacci again and again

思路:求1000以内的每个数的sg值,最后异或为0则先手必败,否则先手输
因为m,n,p都小于1000,所以只要求前15个斐波那契数就可以了 ,打表解决;
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int fb[]={1,2,3,5,8,13,21,34,55,89,144,233,377,610,987};
int sg[1001];
bool b[1001];
int m,n,p;
void getsg()
{
    memset(sg,0,sizeof(sg));
    for(int i=1;i<=1000;i++)
    {
        memset(b,true,sizeof(b));
        for(int j=0;j<15;j++)
        {
            if(i<fb[j])
                break;
            b[sg[i-fb[j]]]=false;
        }
        for(int j=0;j<=1000;j++)
            if(b[j])
           {
               sg[i]=j;break;
           }
    }
}
int main()
{
    getsg();
    while(~scanf("%d%d%d",&m,&n,&p) && m)
    {
        int sum=0;
        sum=sum^sg[m]^sg[n]^sg[p];
        if(sum)
            printf("Fibo\n");
        else
            printf("Nacci\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值