hdu 2516 取石子游戏 (博弈)

取石子游戏

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2328    Accepted Submission(s): 1328


Problem Description
1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍。取完者胜.先取者负输出"Second win".先取者胜输出"First win".
 
Input
输入有多组.每组第1行是2<=n<2^31. n=0退出.
 
Output
先取者负输出"Second win". 先取者胜输出"First win". 
参看Sample Output.
 
Sample Input
2 13 10000 0
 
Sample Output
Second win Second win First win
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  2509 2512 2510 1524 2515 
 
 1 //0MS    232K    345 B    G++    
 2 /*
 3 
 4     先取为负的情况符合斐波那契数列. 
 5 
 6 */
 7 #include<stdio.h>
 8 int main(void)
 9 {
10     int n;
11     int a[50]={0,1};
12     for(int i=2;i<50;i++)
13         a[i]=a[i-1]+a[i-2];
14     while(scanf("%d",&n),n)
15     {
16         int flag=0;
17         for(int i=1;i<50;i++)
18             if(n==a[i]) flag=1;
19         if(flag) puts("Second win");
20         else puts("First win");
21     }
22     return 0;
23 }
原文地址:https://www.cnblogs.com/GO-NO-1/p/3489284.html