HDU-1907-anti-sg

题目
经典的anti-nim题目。
和普通的nim差不多,判断结局的方式不一样:游戏的SG函数不为0且游戏中某个单一游戏的SG函数值大于1,游戏的SG函数为0且没有某个单一游戏的SG函数大于1,先手必胜。
ac代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
namespace {
  template <typename T> inline void read(T &x) {
    x = 0; T f = 1;char s = getchar();
    for(; !isdigit(s); s = getchar()) if(s == '-') f = -1;
    for(;  isdigit(s); s = getchar()) x = (x << 3) + (x << 1) + (s ^ 48);
    x *= f;
  }
}
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (int i = (n); i < (m); i++)
#define _rep(n,m,i) for (int i = (n); i <= (m); i++)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define lowbit(x) x & (-x)
#define pii pair<int,int>
int main() { 
  int n, m, t;
  cin >> t;
  while(t--) { 
    int sgs = 0, cnt = 0;
    cin >> n;
    while(n--) { 
      cin >> m;
      if(m > 1) cnt++;
      sgs ^= m;
    } 
    if(cnt) { 
      if(sgs) cout << "John\n";
      else cout << "Brother\n";
    } 
    else { 
      if(sgs) cout << "Brother\n";
      else cout << "John\n";
    } 
  } 
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值