取石子游戏
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6750 Accepted Submission(s): 4069
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 Output.
Sample Input
2 13 10000 0
Sample Output
Second win Second win First win
Source
ECJTU 2008 Autumn Contest
Recommend
lcy | We have carefully selected several similar problems for you: 2509 2512 1536 2510 1907
点击打开链接
属于斐波那契博弈板子题,先打表再找,当不是斐波那契数先手必胜,否则后手必胜
#include<stdio.h>
typedef long long ll;
ll fb[60];
void init()
{fb[1]=1;fb[2]=1;for(int i=3;i<=59;i++)fb[i]+=fb[i-1]+fb[i-2];
}
int main()
{ll n;init();while(scanf("%lld",&n) && n){int flag=1;for(int i=1;i<=59;i++) {if(n==fb[i]){flag=0;break;}}if(flag)printf("First win\n");elseprintf("Second win\n");} return 0;
}