您的位置:首页 > 其它

GYM 100090 H.Game with the Stones(博弈论)

2017-03-07 18:43 1016 查看
^%Description

n堆石子,每次要把所有数量不小于2的堆分成两个非空堆,谁不能分谁输,Constantine

和Mike轮流分,Constantine先手,双方均采取最佳策略,问谁必胜

Input

第一行一整数n表示石子堆数,之后n个整数a[i]表示每堆石子数量(1<=n<=100,1<=a[i]<=1e9)

Output

输出谁必胜

Sample Input

4

2 4 6 8

Sample Output

Constantine

Solution

显然结果只与石子数最多的一堆有关,对于最大堆x,其后继状态只有(x+1)/2,….,x这(x+1)/2个状态,如果这些状态全部必胜则当前状态必败,否则当前状态必胜,反过来看,一个必败状态y能够影响的最大状态是2*y,也就是说如果y是必败态,则y+1,y+2,…,2*y都是必胜态,2*y+1是必败态,而1是必败态,所以从1开始推可知所有2^m-1都是必败态,其他都是必胜态

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 1111
int main()
{
int n;
while(~scanf("%d",&n))
{
int a,ans=0;
while(n--)
{
scanf("%d",&a);
ans=max(ans,a);
}
ans++;
int gg=1;
while(ans)
{
if(ans<=2)break;
if(ans&1)gg=0;
ans/=2;
}
printf("%s\n",gg==0?"Constantine":"Mike");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: