首页 > 其他 > 详细

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

时间:2014-03-31 03:36:27      阅读:448      评论:0      收藏:0      [点我收藏+]

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;
}


1408: The Game(博弈论)尼姆博弈,布布扣,bubuko.com

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

原文:http://blog.csdn.net/acvcla/article/details/22613359

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!