HDU 1907

博弈入门题吧。

把尼姆博弈推广到n堆,都是用异或运算。还有个总结的地方是,只要先手面对的是奇异局势,则胜负都掌握在后手。本题,题目要求是最后拿完的输,尼姆博弈是最后拿完的赢。但实际上优先权都掌握在后手,前提是先手面对的是奇异局势。

本题还要注意一下每堆都是1的情况。

最后还是膜拜一下OI大神,推荐一个博客

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<iostream>
 5 #include<queue>
 6 #include<stack>
 7 #include<cmath>
 8 #include<algorithm>
 9 #include<malloc.h>
10 using namespace std;
11 #define clc(a,b) memset(a,b,sizeof(a))
12 #define inf 0x3f3f3f3f
13 const int N=10010;
14 #define LL long long
15 const double eps = 1e-5;
16 const double pi = acos(-1);
17 // inline int r(){
18 //     int x=0,f=1;char ch=getchar();
19 //     while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
20 //     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
21 //     return x*f;
22 // }
23 
24 int main(){
25     int T;
26     scanf("%d",&T);
27     while(T--){
28        int n;
29        scanf("%d",&n);
30        bool flag=false;
31        int ans=0;
32        for(int i=1;i<=n;i++){
33             int x;
34             scanf("%d",&x);
35             if(x>1) flag=true;
36             ans^=x;
37        }
38        if(!flag){
39         if(n&1){
40             printf("Brother
");
41         }
42         else 
43             printf("John
");
44        }
45        else{
46         if(ans==0){
47             printf("Brother
");
48         }
49         else{
50             printf("John
");
51         }
52        }
53     }
54     return 0;
55 }
View Code
原文地址:https://www.cnblogs.com/ITUPC/p/5417344.html