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 }

 

posted @ 2017-03-16 19:21  BBBob  阅读(168)  评论(0编辑  收藏  举报