HDU2516 取石子游戏

 1 /*
 2  HDU2516 取石子游戏
 3  http://acm.hdu.edu.cn/showproblem.php?pid=2516
 4  博弈论 斐波那契博弈
 5  *
 6  *
 7  *
 8  */
 9 #include <cstdio>
10 #include <algorithm>
11 #include <cstdlib>
12 #include <cstring>
13 #include <queue>
14 //#define test
15 using namespace std;
16 const int Nmax=50;
17 long long f[Nmax];
18 int cnt;
19 int is(int n)
20 {
21     for(int i=1;i<=cnt;i++)
22         if(n==f[i])
23             return 1;
24     return 0;
25 }
26 int main()
27 {
28     f[1]=1;
29     f[2]=1;
30     for(int i=3;i<Nmax;i++)
31     {
32         f[i]=f[i-1]+f[i-2];
33         if(f[i]>2147483648LL)
34         {
35             #ifdef test
36             printf("%d\n",i);
37             printf("yes!\n");
38             #endif
39             cnt=i-1;
40             break;
41         }
42     }
43     int n;
44     while(scanf("%d",&n)&&n)
45     {
46         if(is(n))
47             printf("Second win\n");
48         else
49             printf("First win\n");
50     }
51     return 0;
52 }

 

转载于:https://www.cnblogs.com/BBBob/p/6561167.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值