首页 > 其他 > 详细

HDU2516 取石子游戏

时间:2017-03-16 20:23:01      阅读:358      评论:0      收藏:0      [点我收藏+]
 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 }

 

HDU2516 取石子游戏

原文:http://www.cnblogs.com/BBBob/p/6561167.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!