neuoj1408博弈



1408: The Game

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

题目描述

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

提示

来源

[ 提交][ 状态][ 讨论版]

//neu1408

#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<map>
const int MAX=0xfffffff;
using namespace std;
int main( )
{
   // freopen("1.txt","r",stdin);
    int t;
    while(cin>>t)
    {
        while(t--)
        {
            int n;
            cin>>n;
            int num=0;
            int num1=0;
            int num2=0;
            while(n--)
            {
                int t;
                cin>>t;
                num^=t;
                if(t==1)
                    num1++;
                else
                    num2++;
            }
            if(num&&num2)   //S2,S1态,必胜
                cout<<"John"<<endl;
            else if(!num2&&!num1%2)  //T0态必胜
                cout<<"John"<<endl;
            else
                cout<<"Brother"<<endl;
        }
    }
    return 0;
}

1408: The Game

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

题目描述

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

提示

来源

[ 提交][ 状态][ 讨论版]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值