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
这种博弈叫做斐波那契博弈….
是通过打表看出规律来的…
以后要对斐波那契敏感一点了
我做这个题的失败就是表达到7就没打下去
我应该打到10的
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
map<ll, int>mp;
int main()
{
ll q = 1, w = 1;
for (ll a = 1; a <= 50; a++)
{
mp[q + w] = 1;
ll e = q + w;
q = w;
w = e;
}
ll n;
while (cin >> n)
{
if (n == 0)break;
if (mp[n])cout << "Second win" << endl;
else cout << "First win" << endl;
}
}