ACM HDU 2516 取石子游戏(博弈)

取石子游戏

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


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
 
 
 
#include<stdio.h>
int main()
{
int m[45],i,n;
m[
0]=2;
m[
1]=3;
for(i=2;i<45;i++)
m[i]
=m[i-1]+m[i-2];
while(scanf("%d",&n),n)
{
for(i=0;i<45;i++)
{
if(m[i]==n)break;
}
if(i==45) printf("First win\n");
else printf("Second win\n");
}
return 0;
}

你可能感兴趣的:(ACM)