1408: The Game(博弈论)尼姆博弈

1408: The Game

时间限制: 1 Sec   内存限制: 256 MB
提交: 54   解决: 25
[ 提交][ 状态][ 讨论版]

题目描述

John and his brother are playing a game. There are several piles of stones. At first John has to pick up some stones from one pile. Then his brother has to make a turn. And so on. Everyone has to pick up at least one stone during his turn. If John (or his brother) will pick up the last stone, he will be considered as a looser.
Both of players are using optimal game strategy. John starts first always.

输入

 The first line of input contains a single integer T (1<= T <= 400) indicating the number of test cases. Each test case starts with number N of piles (1<= N <= 47). Then the next line will contain N integers Si (1<= Si <= 4700), separated by spaces – amount of stones of i-th pile.

输出

Output "Jhon" if Jhon win the game, output "Brother" in other case

样例输入

2
3
3 5 1
1
1

样例输出

John
Brother

#include<stdio.h>
int main()
{
    int a[50];
    int T,n,num1,num2,ans;
    scanf("%d",&T);
 
    while(T--)
    {
        scanf("%d",&n);
        ans=num1=num2=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",a+i);
            if(a[i]==1)
            num1++;         
            else
            num2++;        
            ans^=a[i];     
        }
        if((ans&&num2!=0)||(!ans&&num2==0))
        printf("John\n");
        else                                
        printf("Brother\n");
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值