题目简化出来就是一个NIM问题,只不过胜利条件变成了最后一个取的输掉
贾志豪的那篇文章里面有针对这个问题进行了证明:
对于任意一个Anti-SG游戏,如果我们规定当局面中所有的单一游戏的SG值为0时,游戏结束,则先手必胜当且仅当:(1)游戏的SG函数不为0且游戏中某个单一游戏的SG函数大于1;(2)游戏的SG函数为0且游戏中没有单一游戏的SG函数大于1。
证明反正我也没看懂也暂时没时间看了……以后慢慢品读,先MARK下
应用下来其实就是加一个大于1的判断:
AC代码:
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
int a;
int temp=0;
int num=0;
for(int i=1;i<=n;i++)
{
cin>>a;
if(a>1) num++;
temp^=a;
}
if(temp)
{
if(num>=1) cout<<"John"<<endl;
else cout<<"Brother"<<endl;
}
else
{
if(num<1) cout<<"John"<<endl;
else cout<<"Brother"<<endl;
}
}
}