• HDU 1907 John


    John

    Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1786    Accepted Submission(s): 966

    Problem Description
    Little John is playing very funny game with his younger brother. There is one big box filled with M&Ms of different colors. At first John has to eat several M&Ms of the same color. Then his opponent has to make a turn. And so on. Please note that each player has to eat at least one M&M during his turn. If John (or his brother) will eat the last M&M from the box he will be considered as a looser and he will have to buy a new candy box.
    Both of players are using optimal game strategy. John starts first always. You will be given information about M&Ms and your task is to determine a winner of such a beautiful game.
     
    Input
    The first line of input will contain a single integer T – the number of test cases. Next T pairs of lines will describe tests in a following format. The first line of each test will contain an integer N – the amount of different M&M colors in a box. Next line will contain N integers Ai, separated by spaces – amount of M&Ms of i-th color.
    Constraints: 1 <= T <= 474, 1 <= N <= 47, 1 <= Ai <= 4747
     
    Output
    Output T lines each of them containing information about game winner. Print “John” if John will win the game or “Brother” in other case.
     
    Sample Input
    2
    3
    3 5 1
    1
    1
     
    Sample Output
    John
    Brother
     
    Source
     
    Recommend
     
     
    题意:转化为一对若干堆的火柴,两人依次从中取,规定每次只能从一堆去若干个,
            可以将其全部取走,但不可取,最后去完的为输。
            因为是最后取完为输的,那么......现在没有推出来自己的方法。
            按照,作者的方法,T2 S0为输。否则是赢的。
    代码:
     
    #include<stdio.h>
    int f[48];
    int main()
    {
        int i,n,m,t,num1,num2;
        while(scanf("%d",&t)>0)
        {
            while(t--)
            {
                scanf("%d",&n);
                m=0;num1=0;num2=0;
                for(i=1;i<=n;i++)
                {
                    scanf("%d",&f[i]);
                    m=m^f[i];
                    if(f[i]==1) num1++;
                    if(f[i]>1) num2++;
                }
                if(m==0)//qi yi
                {
                    if(num2>=2)
                        printf("Brother\n");
                    else printf("John\n");
                }
                if(m>0) //fei qi yi
                {
                    if(num1==n)
                        printf("Brother\n");
                    else printf("John\n");
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    centos7.6 使用yum安装mysql5.7
    解决hadoop本地库问题
    docker-compose 启动警告
    docker 安装zabbix5.0 界面乱码问题解决
    docker 部署zabbix问题
    zookeeper 超时问题
    hbase regionserver异常宕机
    (转载)hadoop 滚动升级
    hadoop Requested data length 86483783 is longer than maximum configured RPC length
    zkfc 异常退出问题,报错Received stat error from Zookeeper. code:CONNECTIONLOSS
  • 原文地址:https://www.cnblogs.com/tom987690183/p/3102792.html
Copyright © 2020-2023  润新知