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

时间:2023-03-08 20:44:34
BZOJ 1022: [SHOI2008]小约翰的游戏John [SJ定理]

传送门


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

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

先手必胜:

$1.\ sg \neq 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=;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
} int n,a;
int main(){
freopen("in","r",stdin);
int T=read();
while(T--){
n=read();
int sg=,flag=;
for(int i=;i<=n;i++) a=read(),sg^=a,flag|=(a>);
if( (sg!= && flag)||(sg== && !flag) ) puts("John");
else puts("Brother");
}
}