题意:
给你n堆石子,两人轮流取某一堆中任意数量的石子,至少拿走一个,拿走最后一个石子的人输,问在最佳决策下谁会获胜
分析:
Anti-SG游戏:
1. 使得决策集合为空的游戏者败
2. 其余规则与SG游戏一致
SJ定理:
对于任意一个Anti−SG游戏,如果定义所有子游戏的SG值为0时游戏结束,先手必胜的条件:
1. 全局游戏的SG值为0且所有子游戏SG值均不大于1
2. 全局游戏的SG值不为0且至少存在一个子游戏SG值大于1
代码:
#include <bits/stdc++.h>
using namespace std;
int main(){
int t,n,v;
cin >> t;
while(t--){
cin >> n;
bool vis = false;
int sg = 0;
while(n--){
cin >> v;
sg ^= v;
if(v > 1) vis = true;
}
if((sg&&vis) || (!sg&&!vis)) puts("John");
else puts("Brother");
}
return 0;
}