SHOI2008 小约翰的游戏John

题目描述

题解:

倒过来的$Nim$游戏。

但是输赢的判定就不同于$Nim$游戏。

一个局势先手必败当且仅当满足:

1.单一游戏的$SG$均不大于$1$且游戏的$SG$值为$0$;

2.某个游戏的$SG$大于$1$且游戏的$SG$值不为$0$。

我不会证……

代码:

#include<cstdio>
#include<cstring>
const int N = 55;
int T,n,a[N];
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        int tmp = 0,mx = 0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            tmp^=a[i];
            if(a[i]>mx)mx=a[i];
        }
        int ans = 0;
        if(!tmp&&mx<=1)ans = 1;
        if(tmp&&mx>1)ans = 1;
        puts(ans?"John":"Brother");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/LiGuanlin1124/p/10351706.html