hdu 2516 取石子游戏

取石子游戏

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


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
 找规律,斐波那契数列
 1 #include<iostream>
 2 #include<string>
 3 #include<cstdio>
 4 #include<vector>
 5 #include<queue>
 6 #include<stack>
 7 #include<set>
 8 #include<algorithm>
 9 #include<cstring>
10 #include<stdlib.h>
11 #include<math.h>
12 using namespace std;
13 #define ll __int64
14 set<ll>ko;
15 int main(){
16    double mm=pow(2,31);
17     ll a=2,b=3;
18     ko.insert(2);ko.insert(3);
19     while(a+b<mm){
20         ko.insert(a+b);
21         ll tt=b;
22         b=a+b;
23         a=tt;
24     }
25     int n;
26     while(cin>>n,n){
27         if(ko.count(n)) cout<<"Second win"<<endl;
28         else cout<<"First win"<<endl;
29     }
30 }

 

posted on 2014-08-23 23:07  天凉了  阅读(145)  评论(0编辑  收藏  举报

导航