Anti-nim博弈 John poj3480

传送门:点击打开链接

题意:和nim游戏一样,只不过取最后一个石子的人输。

思路:有一个SJ定理,是专门用来求Anti-nim游戏的,如下

SJ定理
SG函数的求法一模一样,最后如果只有一堆,也能用SJ定理
如果为Anti-Nim游戏,如下情况先手胜
SG异或和为0,且单个游戏的SG全部<=1
SG异或不为0,且存在单个游戏的SG>1,即<=1的个数不等于独立游戏个数

#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define fuck(x) cout<<"["<<x<<"]"
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w+",stdout)
using namespace std;
typedef long long LL;

const int MX = 100 + 5;

int A[MX];
/*
SJ定理
SG函数的求法一模一样,最后如果只有一堆,也能用SJ定理
如果为Anti-Nim游戏,如下情况先手胜
SG异或和为0,且单个游戏的SG全部<=1
SG异或不为0,且存在单个游戏的SG>1,即<=1的个数不等于独立游戏个数
*/
int main() {
    int T, n;
    scanf("%d", &T);
    while(T--) {
        scanf("%d", &n);
        int sum = 0, cnt = 0;
        for(int i = 1; i <= n; i++) {
            scanf("%d", &A[i]);
            sum ^= A[i];
            cnt += (A[i] <= 1);
        }
        if(sum == 0 && cnt == n) printf("John\n");
        else if(sum != 0 && cnt != n) printf("John\n");
        else printf("Brother\n");
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值