取石子游戲
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1394 Accepted Submission(s): 780
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
ECJTU 2008 Autumn Contest
Recommend
lcy
必敗點是斐波那契數列
[cpp]
#include<iostream>
#include<cstdlib>
#include<stdio.h>
using namespace std;
#define ll __int64
ll f[45];
int main()
{
f[0]=2;f[1]=3;
for(int i=2;i<=44;i++)
f[i]=f[i-1]+f[i-2];
ll n;
while(scanf("%I64d",&n)&&n)
{
int i;
for(i=0;i<=44;i++)
{
if(f[i]==n)
break;
}
if(i<44) puts("Second win");
else puts("First win");
}
}
/*
Sample Input
2
13
10000
0
Sample Output
Second win
Second win
First win
*/