POJ 3048 John <Anti-SG(SJ定理)>

题目链接

分析:Anti-SG游戏。直接套SJ定理就好了(参见贾志豪论文《组合游戏略述——浅谈SG游戏的若干拓展即变形》Chapter.2)
截图自论文

代码:
c++

#include <iostream>
#include <algorithm>
using namespace std;

int t,n,a;

int main(){
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--){
        cin>>n;
        int max_SG=0;
        int res=0;
        while(n--){
            cin>>a;
            res^=a;
            max_SG=max(max_SG,a);
        }
        if(res){
            cout<<(max_SG>1?"John":"Brother")<<endl;
        }
        else{
            cout<<(max_SG>1?"Brother":"John")<<endl;
        }
    }
    return 0;
}

python

def main:
    t=int(input())
    for i in range(0,t):
        max_SG=0
        res=0
        n=int(input())
        for i in range(0,n):
            a=int(input())
            res^=a
            if max_SG<a:
                max_SG=a
        if res:
            if max_SG>1:
                print('John\n')
            else:
                print('Brother\n')
        else:
            if max_SG>1:
                print('Brother\n')
            else:
                print('John\n')

if __name__=='__main__':
    main()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值