zoukankan      html  css  js  c++  java
  • HDUOJ----John

    John

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


    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
    lcy
    简单的nim博弈.....(但是要注意全部为1的情况)....那是就不是nim博弈啦!!
    代码:我想说的是,要把名字看清楚,开始将Johe---打错了...打成jone  ,哎!!,尼玛,那叫一个错呀!!
    //http://acm.hdu.edu.cn/showproblem.php?pid=1907
    #include<iostream>
    #include<vector>
    #include<cstdio>
    using namespace std;
    
    int main()
    {    
        int t,n,i,x;
        bool flag ;
        cin>>t;
        while(t--)
        {
            scanf("%d",&n);
            vector<int>num(n+1);
            x=0,flag=false;
            for(i=0;i<n;i++)
            {
                scanf("%d",&num[i]);
                 x^=num[i];
            }
            for(i=0;i<n;i++)
            {
                 if(num[i]>1)
                 {
                   flag=true;
                   break;
                 }
            }
            if(flag)
            {
                if(x)     puts("John");
                else    puts("Brother");
            }
            else
            {
                if(n&1)   
                     puts("Brother");  //奇数 win
                else   
                    puts("John");   //偶数 win
            }
        }
        return 0;
    }
  • 相关阅读:
    Server.MapPath()
    如何系统学习网络攻击技术
    查询数据库中有多少表、视图、存储过程
    测试种类
    linq使用Distinct()
    ASPxPivotGrid隐藏列
    Jenkins:Linux下安装部署步骤
    Jenkins:【测试设计】使用jenkins 插件Allure生成漂亮的自动化测试报告
    Python:Python 自动化测试框架 unittest 和 pytest 对比
    Jenkins:插件安装方式及插件下载地址
  • 原文地址:https://www.cnblogs.com/gongxijun/p/3254560.html
Copyright © 2011-2022 走看看