John

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

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
 

哎呀卧槽。。。

之前看nim游戏的论文,性子太急,看了一半(拿最后一个胜的情况),然后以为自己弄懂了,然后遇到这个题就有点懵逼,再把论文看完,发现之前自己理解得并不是很透彻。

无论拿最后一个胜还是拿最后一个败,都是在争夺S1状态(只有一个充裕堆)。仔细一想,确实是这样,当到达S1状态,玩家可以决定下一个状态,即把下一个状态变为T0或S0

也就是说谁争夺到S1,谁就必胜。

在拿最后一个败的情况中,当所有堆为孤单堆时,需要特殊判断一下,原因容易想到。

博弈这方面,还需多多练习,多多揣摩!!!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<cmath>
using namespace std; int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int res=,num;
int flag=;
for(int i=; i<n; i++)
{
scanf("%d",&num);
if(num>)
flag=;
res^=num;
}
if(flag)
{
if(res>)
printf("John\n");
else
printf("Brother\n");
}
else
{
if(n%==)
printf("John\n");
else
printf("Brother\n");
}
}
return ;
}
 

HDU_1907_基础博弈nim游戏的更多相关文章

  1. HDU 1850 Being a Good Boy in Spring Festival(博弈·Nim游戏)

    Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32 ...

  2. $NIM$游戏小总结

    $umm$可能之后会写个博弈论总结然后就直接把这个复制粘贴上去就把这个删了 但因为还没学完所以先随便写个$NIM$游戏总结趴$QAQ$ 首先最基础的$NIM$游戏:有$n$堆石子,每次可以从一堆中取若 ...

  3. Nim && Grundy (基础博弈游戏 )

    通常的Nim游戏的定义是这样的:有若干堆石子,每堆石子的数量都是有限的,合法的移动是“选择一堆石子并拿走若干颗(不能不拿)”,如果轮到某个人时所有的石子堆都已经被拿空了,则判负(因为他此刻没有任何合法 ...

  4. [hihoCoder] 博弈游戏·Nim游戏

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 今天我们要认识一对新朋友,Alice与Bob.Alice与Bob总是在进行各种各样的比试,今天他们在玩一个取石子的游戏.在 ...

  5. hihocoder 1163 博弈游戏·Nim游戏

    1163 : 博弈游戏·Nim游戏 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 今天我们要认识一对新朋友,Alice与Bob. Alice与Bob总是在进行各种各样的 ...

  6. 51Nod 1069:Nim游戏(尼姆博弈)

    1069 Nim游戏  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 有N堆石子.A B两个人轮流拿,A先拿.每次只能从一堆中取若干个,可将一堆全取走, ...

  7. Nim博弈(nim游戏)

    http://blog.csdn.net/qiankun1993/article/details/6765688 NIM 游戏 重点结论:对于一个Nim游戏的局面(a1,a2,...,an),它是P- ...

  8. hiho一下 第四十五周 博弈游戏·Nim游戏·二 [ 博弈 ]

    传送门 题目1 : 博弈游戏·Nim游戏·二 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Alice和Bob这一次准备玩一个关于硬币的游戏:N枚硬币排成一列,有的正面 ...

  9. NIM游戏,NIM游戏变形,威佐夫博弈以及巴什博奕总结

    NIM游戏,NIM游戏变形,威佐夫博弈以及巴什博奕总结 经典NIM游戏: 一共有N堆石子,编号1..n,第i堆中有个a[i]个石子. 每一次操作Alice和Bob可以从任意一堆石子中取出任意数量的石子 ...

随机推荐

  1. HDU 5446 Unknown Treasure

    Unknown Treasure Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  2. 在全局对象(不是指针)的构造函数里不要对std集合做太多操作

    写MaxvisionOnvif的时候,我用个宏把每个Command类注册到了CommandBuilder里面,通过全局对象初始化实现的,如下: void CommandBuilder::Registe ...

  3. Spring MVC-集成(Integration)-生成Excel示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_excel.htm 说明:示例基于Spring MVC 4.1.6. 以下示例显示 ...

  4. N天学习一个linux命令之xargs

    用途 标准输入流读取参数(空格或者换行符分隔),传递给需要执行的命令 用法 xargs [options] [command [initial-arguments]] 常用选项 --arg-file= ...

  5. AngularJS:让submit重新生效

    当我们在html中声明了ng-app后,form的submit就会失效,必须通过angularJS来处理.如果这时还是想用普通的方式提交的话,需要修改form标签,如下所示: <form met ...

  6. 关于strace的一点东西

    好久没写博客了,感觉有点羞愧,认为自己也应该静下心来利用自己可分配的时间去提升自己.        尽管近期在看一些Python的东西,但是认为自己还是不能忘记本行啊,Linux C的一些东西必须一直 ...

  7. leetcode第一刷_Same Tree

    回来更博客的时候才发现.这道题不是跟推断树是不是对称的很相像吗.这个也是用了两个指针同一时候递归啊,有时候思维的局限真可笑. class Solution { public: bool isSameT ...

  8. linux(centos)下安装git并上传代码些许步骤(亲自验证过的步骤)

     曾经听说了好多次github,但直到近期才第一次学习使用github来托管自己在linux下的代码! 说实话.我自己在使用的时候从网上查了好多教程.但总认为难以掌握(步骤过于繁琐),自己操作的时候还 ...

  9. SecureCRT——设置打印中文字符

    1. 设置方法 使用SecureCRT打印由STM32发送的中文字符提示信息,显示乱码.在网上找了一些链接,再加上自己摸索,终于出了能够让SecureCRT打印中文的方法. 设置以下几个地方即可. 1 ...

  10. spring:为javabean的集合对象注入属性值

    spring:为JavaBean的集合对象注入属性值 在 spring 中可以对List.Set.Map 等集合进行配置,不过根据集合类型的不同,需要使用不同的标签配置对应相应的集合. 1.创建 Ts ...