尼姆博弈HDU1907

HDU1907 http://acm.hdu.edu.cn/showproblem.php?pid=1907

两种情况1.当全是1时,要看堆数的奇偶性

          2.判断是奇异局势还是非奇异局势

代码:

 1 #include<stdio.h>
 2 #include<iostream>
 3 using namespace std;
 4 int main()
 5 {
 6     int m,n;
 7     cin>>n;
 8     while(n--)
 9     {
10         int temp=0;
11         int ans=0;
12         int a[50000];
13         cin>>m;
14         for(int i=0; i<m; i++)
15         {
16             cin>>a[i];
17             ans^=a[i];
18             if(a[i]>1)
19                 temp=1;
20         }
21 
22 
23         if(temp==0)
24         {
25             if(m%2==0)
26             {
27                 cout<<"John"<<endl;
28 
29             }
30             else
31             {
32                 cout<<"Brother"<<endl;
33 
34             }
35         }
36         else
37         {
38 
39 
40             if(ans==0)
41             {
42                 cout<<"Brother"<<endl;
43             }
44             else
45                 cout<<"John"<<endl;
46 
47         }
48     }
49 }
View Code
你若盛开,清风自来...
原文地址:https://www.cnblogs.com/shangjindexiaoqingnian/p/5711706.html