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.

博弈

 #include<stdio.h>
#include<string.h> int main(){
int T;
while(scanf("%d",&T)!=EOF){
while(T--){
int n;
scanf("%d",&n);
int i,num=,sum=;
for(i=;i<=n;i++){
int a;
scanf("%d",&a);
sum^=a;
if(a!=)num++;
}
if((num==&&sum==)||(sum!=&&num>))printf("John\n");
else printf("Brother\n");
}
}
return ;
}

hdu1907 John 博弈的更多相关文章

  1. HDU1907 John

    Description Little John is playing very funny game with his younger brother. There is one big box fi ...

  2. POJ 3480 John [博弈之Nim 与 Anti-Nim]

    Nim游戏:有n堆石子,每堆个数不一,两人依次捡石子,每次只能从一堆中至少捡一个.捡走最后一个石子胜. 先手胜负:将所有堆的石子数进行异或(xor),最后值为0则先手输,否则先手胜. ======== ...

  3. 尼姆博弈HDU1907

    HDU1907 http://acm.hdu.edu.cn/showproblem.php?pid=1907 两种情况1.当全是1时,要看堆数的奇偶性 2.判断是奇异局势还是非奇异局势 代码: #in ...

  4. John(博弈)

    Description Little John is playing very funny game with his  younger brother. There  is one big box ...

  5. hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)

    Problem Description Little John is playing very funny game with his younger brother. There is one bi ...

  6. HDU - 1907 John 反Nimm博弈

    思路: 注意与Nimm博弈的区别,谁拿完谁输! 先手必胜的条件: 1.  每一个小游戏都只剩一个石子了,且SG = 0. 2. 至少有一堆石子数大于1,且SG不等于0 证明:1. 你和对手都只有一种选 ...

  7. POJ 3480 John(SJ定理博弈)题解

    题意:n堆石头,拿走最后一块的输 思路:SJ定理:先手必胜当且仅当:(1)游戏的SG函数不为0且游戏中某个单一游戏的SG函数大于1:(2)游戏的SG函数为0且游戏中没有单一游戏的SG函数大于1. 参考 ...

  8. HDU1907(尼姆博弈)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  9. POJ 3480 &amp; HDU 1907 John(尼姆博弈变形)

    题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Descri ...

随机推荐

  1. learning ddr mode register MR1

  2. learning ddr reset initialization with stable power

  3. Vue + Element UI 实现权限管理系统(第三方图标库)

    使用第三方图标库 用过Elment的同鞋都知道,Element UI提供的字体图符少之又少,实在是不够用啊,幸好现在有不少丰富的第三方图标库可用,引入也不会很麻烦. Font Awesome Font ...

  4. UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  5. Kafka.net使用编程入门(二)

    1.首先创建一个Topic,命令如下: kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partit ...

  6. 修改placeholder的值---input-placeholder

    input-placeholder .box::input-placeholder 目前所有的浏览器都要加前缀 .box::-webkit-input-placeholder{ color: agba ...

  7. 使用ADO.NET访问、查询和操作数据库

    ADO.ENT的主要组件 提供两个组件,用来访问和处理数据:.NET Framework 数据程序和DataSet(数据集) .NET Framework:是专门为数据处理及快速地只进,只读访问数据而 ...

  8. Docker的安装以及使用Docker安装jenkins,gogs,tomcat(一)

    (1)Docker的安装  官网安装链接 :https://yeasy.gitbooks.io/docker_practice/content/ 卸载旧版本 旧版本的 Docker 称为 docker ...

  9. 十一. Python基础(11)—补充: 作用域 & 装饰器

    十一. Python基础(11)-补充: 作用域 & 装饰器 1 ● Python的作用域补遗 在C/C++等语言中, if语句等控制结构(control structure)会产生新的作用域 ...

  10. 用mysql存储过程代替递归查询

    查询此表某个id=4028ab535e370cd7015e37835f52014b(公司1)下的所有数据 正常情况下,我们采用递归算法查询,如下 public void findCorpcompany ...