HDU - 1907 anti-SG

题意:nim游戏,最后取光为【输】
anti-SG的应用,搬运一下我的摸鱼小笔记

最先看到的应该是分奇偶的非充裕堆判断,若为偶数则先手胜,否则后手胜
按SG分类
SG!=0时
1.只有一堆大于1,先手可以把这堆化为0或者1,然后从上面的结果来看,先手必胜
2.大于一堆大于1,先手可以把SG=0的局面留给对手,先手必胜
3.没有一堆大于1,那就是只有奇数个非充裕堆的情况,先手必败
SG=0时
1.只有一堆大于1,不存在此情况
2.大于一堆大于1,先手无论如何操作,对于后手的局面总有大于一堆大于1,且后手SG!=0,从上面讨论的结果来看,先手必败
3.没有一堆大于1,既只有偶数个非充裕堆的情况,先手必胜

这个过程比较麻烦,要学会利用结论
结论:
单一SG=0时子游戏结束,先手必胜的条件需满足
1.SG!=0且存在单一SG>1
2.SG=0且所有单一SG<=1

那刚才的anti-nim游戏就分别对应于
1.SG!=0且至少一堆大于1
2.SG=0且所有堆为1

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e6+11;
const int oo = 0x3f3f3f3f;
const double eps = 1e-7;
typedef long long ll;
ll read(){
    ll x=0,f=1;register char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
    int T=read();
    while(T--){
        int n=read();
        ll t=0,cnt=0,cnt2=0;
        rep(i,1,n){
            ll x=read();
            t^=x;
            if(x==1) cnt++;
            else cnt2++;
        }
        if(t!=0&&cnt2>=1) printf("John\n");
        else if(t==0&&(cnt==n)&&(cnt%2==0)) printf("John\n");
        else printf("Brother\n");
    }
    return 0;
}

转载于:https://www.cnblogs.com/caturra/p/8652826.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值