zoukankan      html  css  js  c++  java
  • hdu1907 John 博弈

    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.

    博弈

     1 #include<stdio.h>
     2 #include<string.h>
     3 
     4 int main(){
     5     int T;
     6     while(scanf("%d",&T)!=EOF){
     7         while(T--){
     8             int n;
     9             scanf("%d",&n);
    10             int i,num=0,sum=0;
    11             for(i=1;i<=n;i++){
    12                 int a;
    13                 scanf("%d",&a);
    14                 sum^=a;
    15                 if(a!=1)num++;
    16             }
    17             if((num==0&&sum==0)||(sum!=0&&num>0))printf("John
    ");
    18             else printf("Brother
    ");
    19         }
    20     }
    21     return 0;
    22 }
    View Code
  • 相关阅读:
    python 开启多进程的两种方法
    Python
    Python
    路由器配置
    python 自定义报头 实现大文件传输
    python socket
    Spring MVC 实现文件的上传
    SpringMVC异常处理
    SpringMVC 返回值类型,参数传递 解决乱码
    Spring—MVC案例
  • 原文地址:https://www.cnblogs.com/cenariusxz/p/6592341.html
Copyright © 2011-2022 走看看