标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2516
题意分析:乍一看是巴什博弈,后来发现博弈只是个噱头,关键还是找规律。
/*取石子游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3080 Accepted Submission(s): 1790 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 */ //Fibonacci+博弈 #include <cstdio> #include <cstring> const int maxn = 50 + 10; int a[maxn]; void init() { a[1] = 1; a[2] = 2; for(int i = 3; i < maxn; i++) a[i] = a[i-1] + a[i-2]; } int main() { int m; init(); while(~scanf("%d", &m) && m){ int flag = 0; for(int i = 1; i < maxn; i++){ if(a[i] == m){ flag = 1; break; } } if(flag) printf("Second win\n"); else printf("First win\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/ACFLOOD/p/4317240.html