1907 John

题意:

在一个盒子里面有不同颜色的糖果,John和Brother轮流在里面取糖果吃,每次都是John先取。

每次只能取同一种颜色的若干个糖果,不能不取,最后取走糖果的人输。

输出赢家。

思路:

这是一道裸的尼姆博弈,把同一种颜色的看成一堆,就直接套定理的结果就可以了。

如果有不知到尼姆博弈的可以看一下这篇文章

http://www.wutianqi.com/?p=1081

写的不错。

S为利己态,T为利他态。(这个利就是让谁取最后一个)

S0代表超过1的堆数有0个的利己态,S1代表有一个,S2代表有两个或两个以上。T0、T2同理。

必胜态:S2、S1、T0

必输态:T2、S0

Code:

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<bitset>
#include<set>
#include<map>
#include<cctype>
#include<vector>

#define TEST

#define LL long long
#define Mt(f, x) memset(f, x, sizeof(f));
#define xep(i, n) for(int i = 0; i < (n); ++i)
#define rep(i, s, e) for(int i = (s); i <= (e); ++i)
#define dep(i, s, e) for(int i = (s); i >= (e); --i)
#ifdef TEST
    #define See(a) cout << #a << " = " << a << endl;
    #define See2(a, b) cout << #a << " = " << a << ' ' << #b << " = " << b << endl;
    #define debug(a, s, e){ rep(_i, s, e) {cout << a[_i] << ' '; }cout << endl;}
    #define debug2(a, s, e, ss, ee) rep(i_, s, e) {debug(a[i_], ss, ee);}
#else
    #define See(a) {}
    #define See2(a, b) {}
    #define debug(a, s, e) {}
    #define debug2(a, s, e, ss, ee) {}
#endif

const int MAX = 2e9;
const int MIN = -2e9;
const int PI = acos(-1.0);
const double eps = 1e-8;

using namespace std;

const int N = 55;

int a[N];

int nimm(int n)//求状态是T还是S
{
    int ret = a[0];
    for(int i = 1; i < n; ++i)
    {
        ret ^= a[i];
    }
    return ret;
}

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        int n;
        scanf("%d", &n);
        int tem = 0, state;
        for(int i = 0; i < n; ++i)
        {
            scanf("%d", &a[i]);
            if(a[i] != 1)
            {
                ++tem;
            }
        }
        state = nimm(n);
        bool win;
        if(state)
        {
            if(tem == 0)
            {
                win = false;
            }
            else
            {
                win = true;
            }
        }
        else
        {
            if(tem == 0)
            {
                win = true;
            }
            else
            {
                win = false;
            }
        }
        printf("%s\n", win ? "John" : "Brother");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值