反Nim博弈

原文地址:https://blog.csdn.net/xuejye/article/details/78975900

在尼姆博奕中取完最后一颗糖的人为赢家,而取到最后一颗糖为输家的就是反尼姆博奕。这道题就反尼姆

博奕的模型。在尼姆博奕中判断必胜局面的条件是所有堆石子数目相异或不等于0 。  而在反尼姆博奕中判断必胜局

面的条件有两点,满足任意一点先手都能取胜,即必胜局面。   

第一种判别方法:  15ms

                   1:各堆石子数目异或结果不等于0,且存在有石子数目大于1的石子堆。

                   2:各堆石子数目异或结果等于0,且所有石子堆数目全部为1。

第二种判别方法:  0ms

  1、若所有堆的数量都为1, 并且1的数量为偶数先手赢。
  2、若不都为1, 那么判断res即可。

 

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 10010, INF = 0x7fffffff;

int main()
{
    int T;
    cin>> T;
    while(T--)
    {
        int n, res = 0, cnt = 0;
        cin>> n;
        for(int i=0; i<n; i++)
        {
            int w;
            cin>> w;
            res ^= w;
            if(w == 1) cnt++;
        }
        if(res && cnt != n) cout<< "John" <<endl;
        else if(!res && cnt == n) cout<< "John" <<endl;
        else cout<< "Brother" <<endl;


    }

    return 0;
}

 

转载于:https://www.cnblogs.com/WTSRUVF/p/9339499.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值