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

^%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");
    }
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值