HDU_1907_基础博弈nim游戏
John
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 4440 Accepted Submission(s):
2541
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.
– 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
about game winner. Print “John” if John will win the game or “Brother” in other
case.
哎呀卧槽。。。
之前看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游戏的更多相关文章
- 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 ...
- $NIM$游戏小总结
$umm$可能之后会写个博弈论总结然后就直接把这个复制粘贴上去就把这个删了 但因为还没学完所以先随便写个$NIM$游戏总结趴$QAQ$ 首先最基础的$NIM$游戏:有$n$堆石子,每次可以从一堆中取若 ...
- Nim && Grundy (基础博弈游戏 )
通常的Nim游戏的定义是这样的:有若干堆石子,每堆石子的数量都是有限的,合法的移动是“选择一堆石子并拿走若干颗(不能不拿)”,如果轮到某个人时所有的石子堆都已经被拿空了,则判负(因为他此刻没有任何合法 ...
- [hihoCoder] 博弈游戏·Nim游戏
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 今天我们要认识一对新朋友,Alice与Bob.Alice与Bob总是在进行各种各样的比试,今天他们在玩一个取石子的游戏.在 ...
- hihocoder 1163 博弈游戏·Nim游戏
1163 : 博弈游戏·Nim游戏 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 今天我们要认识一对新朋友,Alice与Bob. Alice与Bob总是在进行各种各样的 ...
- 51Nod 1069:Nim游戏(尼姆博弈)
1069 Nim游戏 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 有N堆石子.A B两个人轮流拿,A先拿.每次只能从一堆中取若干个,可将一堆全取走, ...
- Nim博弈(nim游戏)
http://blog.csdn.net/qiankun1993/article/details/6765688 NIM 游戏 重点结论:对于一个Nim游戏的局面(a1,a2,...,an),它是P- ...
- hiho一下 第四十五周 博弈游戏·Nim游戏·二 [ 博弈 ]
传送门 题目1 : 博弈游戏·Nim游戏·二 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Alice和Bob这一次准备玩一个关于硬币的游戏:N枚硬币排成一列,有的正面 ...
- NIM游戏,NIM游戏变形,威佐夫博弈以及巴什博奕总结
NIM游戏,NIM游戏变形,威佐夫博弈以及巴什博奕总结 经典NIM游戏: 一共有N堆石子,编号1..n,第i堆中有个a[i]个石子. 每一次操作Alice和Bob可以从任意一堆石子中取出任意数量的石子 ...
随机推荐
- 【Codeforces 4D】Mysterious Present
[链接] 我是链接,点我呀:) [题意] 要求长度和宽度都严格递增(选择一个序列) 然后你一开始有一个长度和宽度 要求这个一开始所给的长度和宽度能接在你选择的一段连续的长度宽度的开头 (且保持原来的性 ...
- Leetcode 48.旋转矩阵
旋转矩阵 给定一个 n × n 的二维矩阵表示一个图像. 将图像顺时针旋转 90 度. 说明: 你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵.请不要使用另一个矩阵来旋转图像. 示例 1: ...
- mysql 数据的某个范围
select * from table_name where limit num1, num2; num1 : 开始条目 num2 :选择数目
- hdu_1061_Rightmost Digit_201311071851
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Expanding Rods POJ 1905 二分
Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 17050 Accepted: 4503 Description When ...
- 关于Spring的xml文档的简单实用配置
Spring的spring.xml文档的配置 最近在写Spring的配置文件时,发现Spring文档的配置其实没必要那么繁琐记忆,网上的很多文章都写得很繁琐,如果所有的东西按照路径去查找,可以很快的帮 ...
- ZooKeeper的配置文件优化性能(转)
一.前言 ZooKeeper的功能特性通过ZooKeeper配置文件来进行控制管理( zoo.cfg配置文件). ZooKeeper这样的设计其实是有它自身的原因的.通过前面对ZooKeeper的配置 ...
- 完全卸载VS2015的方法
解压ISO文件夹,到根目录下运行命令行: vs_enterprise.exe /uninstall /force 注意:如果安装了Update 3时,就解压最新的ISO,不需要旧的. 卸载完成之后,删 ...
- OpenCV使用GPU
在使用OpenCV2.4.x的时候,以为不用重新编译可以直接使用GPU模块,不过在我使用的时候,发现使用getCudaEnabledDeviceCount()的时候,总是获得是0,于是重新编译Open ...
- ubuntu上java的运行环境jre的安装
如何在Ubuntu 14.04上面安装 java的运行环境 jre 呢,下面直接采用到 oracle 的java 官网下载 对应的 jre 的tar.gz的包 从 root用户切换到 saynoer ...