HDU1907 John 博弈

来源:互联网 发布:宁波mac专柜地址查询 编辑:程序博客网 时间:2024/05/09 07:23
/*cnt == 0:说明每一种颜色都只有一个,相当于一堆石子,每次必须取一个的情况Sg(x) = x % 2。本题题义稍有不同,取走最后一个时是输,所以x = n - 1如果cnt != 0,题义的改变对结果影响*/#include <iostream>  using namespace std;  int value[101];  int main ()  {      int n,sum,temp, t, i, cnt; cin>>t;    while (t--)      {cin>>n;sum = 0;cnt = 0;for(i = 0; i < n; i++){cin>>temp;sum = sum^temp;if(temp > 1)cnt = 1;}if(cnt == 0)sum = ( (n-1) % 2 );        if(sum == 0)cout<<"Brother"<<endl;elsecout<<"John"<<endl;    }      return 0;  }

原创粉丝点击