取石子游戏
Problem Description1堆石子有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
(适用于特殊的题型)
1 #include<iostream> 2 #include<map> 3 using namespace std; 4 int main() 5 { 6 int fib[500]; 7 fib[0] = 1, fib[1] = 2; 8 for (int i = 2; i <= 70;i++) 9 fib[i] = fib[i - 1] + fib[i - 2]; 10 int n; 11 while (cin >> n&&n) 12 { 13 int mark = 0; 14 for (int i = 0; i <= 70; i++) { 15 if (fib[i] == n) mark = 1, cout << "Second win" << endl; 16 if (fib[i] > n) break; 17 } 18 if (!mark) cout << "First win" << endl; 19 } 20 21 return 0; 22 }