题意:取石子游戏,不能取的人为胜
对于任意一个Anti-SG游戏,如果我们规定当局面中所有的单一游戏的SG值为0时,游戏结束,则先手必胜当且仅当:(1)游戏的SG函数不为0且游戏中某个单一游戏的SG函数大于1;(2)游戏的SG函数为0且游戏中没有单一游戏的SG函数大于1。
题中 sg(x)=x
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int flag=0;
int ans=0;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
ans^=a;
if(a>1) flag++;
}
if((ans&&flag)||(ans==0&&flag==0)) cout<<"1"<<endl;
else cout<<"2"<<endl;
}
}