hdu 2516 取石子游戏 (Fibonacci博弈)
Posted getcharzp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 2516 取石子游戏 (Fibonacci博弈)相关的知识,希望对你有一定的参考价值。
取石子游戏
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8159 Accepted Submission(s): 4950
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
2
13
10000
0
Sample Output
Second win
Second win
First win
Second win
Second win
First win
C/C++:
1 #include <map> 2 #include <queue> 3 #include <cmath> 4 #include <vector> 5 #include <string> 6 #include <cstdio> 7 #include <cstring> 8 #include <climits> 9 #include <iostream> 10 #include <algorithm> 11 #define INF 0x3f3f3f3f 12 #define LL long long 13 #define wzf ((1 + sqrt(5.0)) / 2.0) 14 using namespace std; 15 16 __int64 n, fib[45] = {1, 1}; 17 18 void calc() 19 { 20 for (__int64 i = 2; i <= 46; ++ i) 21 fib[i] = fib[i - 1] + fib[i - 2]; 22 } 23 24 bool is_fib() 25 { 26 for (__int64 i = 2; i <= 45; ++ i) 27 { 28 if (fib[i] > n) return false; 29 if (n == fib[i]) 30 return true; 31 } 32 return false; 33 } 34 35 int main() 36 { 37 calc(); 38 while (scanf("%I64d", &n), n) 39 { 40 if (is_fib()) 41 printf("Second win "); 42 else 43 printf("First win "); 44 } 45 return 0; 46 }
以上是关于hdu 2516 取石子游戏 (Fibonacci博弈)的主要内容,如果未能解决你的问题,请参考以下文章