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. 【codeforces 801A】Vicious Keyboard

    [题目链接]:http://codeforces.com/contest/801/problem/A [题意] 一个字符串只由VK组成; 让你修改一个字符; 使得剩下的字符串里面子串VK的个数最大; ...

  2. Industrial Nim

    http://codeforces.com/contest/15/problem/C 题意: 现有n个采石场,第i个采石场有mi堆石子 各堆分别有xi,xi+1……,xi+m-1颗石子 两名选手使用最 ...

  3. Windows学习总结(7)——学会CMD命令提示符的重要性

    作为普通电脑用户,大家接触最多的应该 是可视的操作系统界面.可是如果想真正学好计算机,学习好命令提示符可就是必不可少的.它可以更高效的帮助我们处理问题. 命令提示符是在操作系统中,提示进行命令输入的一 ...

  4. python正则匹配——中文字符的匹配

    # -*- coding:utf-8 -*- import re '''python 3.5版本 正则匹配中文,固定形式:\u4E00-\u9FA5 ''' words = 'study in 山海大 ...

  5. mysql :=和=的区别

    :=和=的区别 = 只有在set和update时才是和:=一样,赋值的作用,其它都是等于的作用.鉴于此,用变量实现行号时,必须用:= := 不只在set和update时时赋值的作用,在select也是 ...

  6. nyoj_524_A-B Problem_201312012035

    A-B Problem 时间限制:1000 ms  |           内存限制:65535 KB 难度:3   描述 A+B问题早已经被大家所熟知了,是不是很无聊呢?现在大家来做一下A-B吧. ...

  7. [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心

    Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵 ...

  8. [转]使用代码去描述WCF配置文件

    转自:使用代码去描述WCF配置文件 在应用程序部署的时候,WCF客户端因为服务器地址的变化,需要修改程序配置文件的地址URL,手动修改很不方便,还会造成错误,所以尽量把描述WCF配置文件的配置使用代码 ...

  9. Linux/CentOS各种服务框架的搭建完整流程

    在2012年的时候,由于要照应新人对Linux以及相关服务的了解和学习,我特地把当时我们创业项目的全部服务搭建过程写成了一篇文档,能够让他们学习而且有所參照. 以下就以这篇文档为底稿,进行一些改动和敏 ...

  10. 2018你应该了解这些.NET面试题

    2018年准备要找.NET开发相关工作的你准备好了吗,下面是小编准备的一些.NET相关的面试题,来阅读一下,也许对你有帮助哦~ 1. 谈谈你对MVC和三层架构的理解. MVC即模型.视图.控制器,模型 ...