BZOJ 1022: [SHOI2008]小约翰的游戏John [SJ定理]

传送门


$anti-nim$游戏,$SJ$定理裸题

规定所有单一游戏$sg=0$结束

先手必胜:

$1. sg eq 0, 某个单一游戏sg >1$

$2. sg = 0, 没有单一游戏 sg > 1$

话说那个$J$竟然是$JiaZhihao$ Orz

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=55;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
    return x*f;
}

int n,a;
int main(){
    freopen("in","r",stdin);
    int T=read();
    while(T--){
        n=read();
        int sg=0,flag=0;
        for(int i=1;i<=n;i++) a=read(),sg^=a,flag|=(a>1);
        if( (sg!=0 && flag)||(sg==0 && !flag) ) puts("John");
        else puts("Brother");
    }
}
原文地址:https://www.cnblogs.com/candy99/p/6545235.html