hdu 1907(Nim博弈)
John
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 4407 Accepted Submission(s): 2520
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.
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
T lines each of them containing information about game winner. Print
“John” if John will win the game or “Brother” in other case.
3
3 5 1
1
1
Brother
中间过程不再赘述:
必胜态: S2,S1,T0.
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <map>
using namespace std; int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
int n,sum = ,v,_cnt=,_cnt1=; ///_cnt 代表孤单堆的数量,_cnt1 代表充裕堆的数量
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&v);
if(v==) _cnt++;
if(v>) _cnt1++;
sum^=v;
}
if(_cnt%&&_cnt1==||_cnt1>=&&sum==){
printf("Brother\n");
}else{
printf("John\n");
}
}
return ;
}
hdu 1907(Nim博弈)的更多相关文章
- HDU 1907 Nim博弈变形
1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...
- HDU 2509 Nim博弈变形
1.HDU 2509 2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...
- hdu 1730 Nim博弈
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1730 Nim博弈为:n堆石子,每个人可以在任意一堆中取任意数量的石子 n个数异或值为0就后手赢,否则先 ...
- HDU - 1850 Nim博弈
思路:可以对任意一堆牌进行操作,根据Nim博弈定理--所有堆的数量异或值为0就是P态,否则为N态,那么直接对某堆牌操作能让所有牌异或值为0即可,首先求得所有牌堆的异或值,然后枚举每一堆,用已经得到的异 ...
- Hdu 1729 Nim博弈
点击打开题目链接 之前没做过这题,因为学弟问到我如果来求该题的sg值,才做了这题. 首先, 是多堆Nim博弈毫无疑问,这题是往一个有固定容量的箱子里放石子,和从一堆石子里面拿出石子是一个道理. 和传统 ...
- HDU 3032 (Nim博弈变形) Nim or not Nim?
博弈的题目,打表找规律还是相当有用的一个技巧. 这个游戏在原始的Nim游戏基础上又新加了一个操作,就是游戏者可以将一堆分成两堆. 这个SG函数值是多少并不明显,还是用记忆化搜索的方式打个表,规律就相当 ...
- HDU 3389 (Nim博弈变形) Game
参考了众巨巨的博客,现在重新整理一下自己的思路. 首先在纸上画了一下转移图: 1 3 4号盒子是不能够再转移卡片到其他盒子中去了的,其他盒子中的卡片经过若干步的转移最终也一定会转移到1 3 4号盒子中 ...
- HDU 1850 (Nim博弈 取胜方案数) Being a Good Boy in Spring Festival
考虑到Bouton定理的证明过程,设n个数的Nim和(异或和)为X,其最高位的1在第k位,那么n个数中一定有个y的第k为也是个1. 将y的数量变为X xor y,那么n的数的Nim和为0,便转为先手必 ...
- HDU 2509 nim博弈
Be the Winner Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
随机推荐
- MapReduce(三) 典型场景(一)
一.mapreduce多job串联 1.需求 一个稍复杂点的处理逻辑往往需要多个 mapreduce 程序串联处理,多 job 的串联可以借助 mapreduce 框架的 JobControl 实现 ...
- 【bzoj4940】这是我自己的发明
Portal --> bzoj4940 Solution (原题这题面到底是..怎么回事啊深深的套路qwq) 感觉自己对根号的算法还是很..没有感觉啊== 实际上这题和bzoj5016没有任何区 ...
- python函数:字符串函数示例
优先掌握的操作 #作用:名字,性别,国籍,地址等描述信息 #定义:在单引号\双引号\三引号内,由一串字符组成 name='egon' #优先掌握的操作: #1.按索引取值(正向取+反向取) :只能取 ...
- .Net并行编程之二:并行循环
本篇内容主要包括: 1.能够转化为并行循环的条件 2.并行For循环的用法:Parallel.For 3.并行ForEach的用法Parallel.ForEach 4.并行LINQ(PLINQ)的用法 ...
- 将本地项目和远程git仓库相连接
有时候写代码,是存在本地的,远程仓库没有对应的代码库,这个时候就需要把本地的代码项目与远程git库连接并推送. 1. 将项目文件添加到仓库中 本地的项目文档: 添加项目文件 git add . 2. ...
- 一小时了解数据挖掘⑤数据挖掘步骤&常用的聚类、决策树和CRISP-DM概念
一小时了解数据挖掘⑤数据挖掘步骤&常用的聚类.决策树和CRISP-DM概念 接前面系列4篇: 一小时了解数据挖掘①:解析常见的大数据应用案例 一小时了解数据挖掘②:分类算法的应用和成熟案例解析 ...
- Spring整合Quartz分布式调度
前言 为了保证应用的高可用和高并发性,一般都会部署多个节点:对于定时任务,如果每个节点都执行自己的定时任务,一方面耗费了系统资源,另一方面有些任务多次执行,可能引发应用逻辑问题,所以需要一个分布式的调 ...
- jquery-load()方法
调用load方法的完整格式是:load( url, [data], [callback] ), 其中: •url:是指要导入文件的地址. •data:可选参数:因为Load不仅仅可以导入静态的html ...
- Metasploit 使用基础
本文将简单介绍一下Kali2 上Metasploit的一些基本使用,包括启动.更新及一个小问题"Module database cache not built yet, using slow ...
- HDU 1081 To The Max (dp)
题目链接 Problem Description Given a two-dimensional array of positive and negative integers, a sub-rect ...