POJ3480 John 博弈论 anti-nim anti-SG

http://poj.org/problem?id=3480

anti-nim其实是anti-SG的一种,就像nim是sg的一种一样。(或者说sg是nim推广?)

看名字就是规则和nim相反,取到最后一个的输。

同样需要求sg函数的异或和,不过先手必胜条件变成了:

1.异或和为0且其中所有元素的sg函数都小于等于1.

2.异或和不为0且其中至少有一个元素的sg函数大于1.

nim中的每一堆的sg函数其实就是这一堆中的石子数,同样,anti-nim的anti-sg函数也是石子数。

这道是anti-nim的模板题。。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<iostream>
 6 #include<map>
 7 #include<ctime>
 8 using namespace std;
 9 const int maxn=1<<13;
10 int n;
11 int main(){
12     int T;scanf("%d",&T);
13     while(T-->0){
14         scanf("%d",&n);
15         int y=0,x,f=0;
16         for(int i=1;i<=n;i++){
17             scanf("%d",&x);
18             y^=x;if(x>1)f=1;
19         }
20         if(((!y)&&(!f))||(y&&f)) printf("John\n");
21         else printf("Brother\n");
22     }
23     return 0;
24 }
View Code

 

posted @ 2018-01-05 13:58  鲸头鹳  阅读(330)  评论(0编辑  收藏  举报