HDU 1907
博弈入门题吧。
把尼姆博弈推广到n堆,都是用异或运算。还有个总结的地方是,只要先手面对的是奇异局势,则胜负都掌握在后手。本题,题目要求是最后拿完的输,尼姆博弈是最后拿完的赢。但实际上优先权都掌握在后手,前提是先手面对的是奇异局势。
本题还要注意一下每堆都是1的情况。
最后还是膜拜一下OI大神,推荐一个博客
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=;
#define LL long long
const double eps = 1e-;
const double pi = acos(-);
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// } int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
bool flag=false;
int ans=;
for(int i=;i<=n;i++){
int x;
scanf("%d",&x);
if(x>) flag=true;
ans^=x;
}
if(!flag){
if(n&){
printf("Brother\n");
}
else
printf("John\n");
}
else{
if(ans==){
printf("Brother\n");
}
else{
printf("John\n");
}
}
}
return ;
}
HDU 1907的更多相关文章
- HDU 1907 Nim博弈变形
1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...
- hdu 1907 (尼姆博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very ...
- hdu 1907 John (anti—Nim)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)http://acm.h ...
- POJ 3480 & HDU 1907 John(尼姆博弈变形)
题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Descri ...
- HDU 1907 John nim博弈变形
John Problem Description Little John is playing very funny game with his younger brother. There is ...
- HDU 1907 (博弈) John
参见上一篇博客,里面有分析和结论. #include <cstdio> int main() { int T; scanf("%d", &T); while(T ...
- hdu 1907 John
很简单的博弈论问题!!(注意全是1时是特殊情况) 代码如下: #include<stdio.h> #include<iostream> using namespace std; ...
- 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 ...
- HDU 1907 John(取火柴博弈2)
传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int ...
随机推荐
- fsockopen
fsockopen — 打开一个网络连接或者一个Unix套接字连接 说明 resource fsockopen ( string $hostname [, int $port = -1 [, int ...
- 用Unity的Animation播放Animator动画Clip
简单的动画,其实不需要Animator动画状态机管理,用Animation播放效率更高,但可能由于历史遗留问题,或网上下载的第三方资源,得到的是Animator资源,可以在Clip的Debug试图下, ...
- SQL中子查询为聚合函数时的优化
测试数据:create table test1 as select * from dba_objects where rownum<=10000;--10000条记录create table t ...
- BZOJ 2818GCD
Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sam ...
- SVN服务器使用(一)
源代码版本控制软件很多,像VSS,SVN还有其他的软件,各有优缺点.Subversion是优秀的版本控制工具,下面主要介绍这个软件的使用. Subversion下载地址: http://subvers ...
- CSS水平、垂直居中小结
我们在实际工作中经常会遇到需要水平居中或者垂直居中的场景,今天我们就来看一下如何设置水平居中和垂直居中. 首先来看水平居中. 一.水平居中设置-行内元素. 如果被设置元素为文本.图片等行内元素时,水平 ...
- 一些常用的jQuery插件
1. X-editable 这个插件能够让你在页面上创建可编辑的元素.它能够使用任何引擎(bootstrap.jquery-ui.jquery),并且包含弹出式和内联模式. 2. Garlic.js ...
- C#变成数据导入Excel和导出Excel
excel 基础 •整个excel 表格叫工作表:workbook:工作表包含的叫页:sheet:行:row:单元格:cell. •excel 中的电话号码问题,看起来像数字的字符串以半角单引号开头就 ...
- sjtu1590 强迫症
Description BS96发布了一套有\(m\)个band柄绘的新badge,kuma先生想要拿到04的badge于是进行了抽抽抽. kuma先生一共抽了\(n\)个badge.他把所有的bad ...
- Java Development Kit (JDK) 发展历程 及新特性
SE(J2SE),standard edition,标准版,是我们通常用的一个版本,从JDK 5.0开始,改名为Java SE. EE(J2EE),enterprise edition,企业版,使用这 ...