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. js匀速运动

    匀速运动      封装匀速运动原理:设置定时器,将传入的ele,设定一个速度,使用定时器获取当前时间的一个位置,加上速度值,给回节点,当节点到达目标位置,判断给他清除定时器. 匀速效果地址:http ...

  2. Cracking The Coding Interview 9.6

    //原文: // // Given a matrix in which each row and each column is sorted, write a method to find an el ...

  3. Android : App通过LocalSocket 与 HAL间通信

    LocalSocket其通信方式与Socket差不多,只是LocalSocket没有跨越网络边界.对于*nix系统来说,“一切皆为文件”,Socket也不例外,Socket按照收发双方的媒介来说有三种 ...

  4. Linux输入子系统 : 按键驱动

    一.Linux input system框架: 1.由输入子系统核心层(input.c),驱动层(gpio_keys.c)和事件处理层(Event Handler)三部份组: 2.主要的三个结构体:i ...

  5. powershell玩转litedb数据库-第二版

    powershell可以玩nosql数据库吗?答案是肯定的.只要这个数据库兼容.net,就可以很容易地被powershell使用. 发文初衷:世界上几乎没有讲powershell调用nosql的帖子, ...

  6. EEPROM读写学习笔记与I2C总线(转)

    reference:https://www.cnblogs.com/uiojhi/p/7565232.html 无论任何电子产品都会涉及到数据的产生与数据的保存,这个数据可能并不是用来长久保存,只是在 ...

  7. Ubuntu 修改 /etc/resolv.conf 被清空 或重启不生效解决

    sudo gedit /etc/NetworkManager/NetworkManager.conf 注释掉 dns=dnsmasq [main] plugins=ifupdown,keyfile,o ...

  8. redis 解析配置文件

    在redis安装文件夹里面有redis.conf,查看配置. 一:基础配置介绍 1.units(单位) --这里可以看到 1k和1kb是不一样的,  units 这里单位是不区分大小写的,are al ...

  9. mybatis-generator没有自动生成代码和Junit测试controller

    本来mybatis的generator想要自动生成增删改的,但是到后来语句就两个select,原因是数据中没有给字段加primary,就不会有删改增. 以及Controller的Junit测试 先导入 ...

  10. <容错性FaultTolerance><Hadoop><Spark>

    Overview 讨论一些常见大数据框架的容错机制 Fault Tolerance in Hadoop MapReduce Heartbeat心跳机制:如果在一定时间内没有收到心跳,则reschedu ...