题目链接:https://cn.vjudge.net/contest/269106#problem/F
题目大意:
1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍。取完者胜.先取者负输出"Second win".先取者胜输出"First win".
解题思路:
斐波那契博弈,n为斐波那契数时先手必败,用map记录一下斐波那契数即可。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll, ll>mp;
int main()
{
ll i, n, a, b, c, len = 1e18;
a = 1;
b = 1;
c = a + b;
mp[1] = 1;
while(c <= len)
{
mp[c] = 1;
a = b;
b = c;
c = a + b;
}
while(scanf("%lld", &n) != EOF)
{
if(n == 0)break;
if(mp[n] == 1)printf("Second win\n");
else printf("First win\n");
}
return 0;
}