博弈入门题吧。

把尼姆博弈推广到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的更多相关文章

  1. HDU 1907 Nim博弈变形

    1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...

  2. hdu 1907 (尼姆博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very ...

  3. hdu 1907 John (anti—Nim)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)http://acm.h ...

  4. POJ 3480 &amp; HDU 1907 John(尼姆博弈变形)

    题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Descri ...

  5. HDU 1907 John nim博弈变形

    John Problem Description   Little John is playing very funny game with his younger brother. There is ...

  6. HDU 1907 (博弈) John

    参见上一篇博客,里面有分析和结论. #include <cstdio> int main() { int T; scanf("%d", &T); while(T ...

  7. hdu 1907 John

    很简单的博弈论问题!!(注意全是1时是特殊情况) 代码如下: #include<stdio.h> #include<iostream> using namespace std; ...

  8. 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 ...

  9. HDU 1907 John(取火柴博弈2)

    传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int ...

随机推荐

  1. 【DB】SQLite学习笔记

    下载”System.Data.SQLite.DLL”,程序中添加引用即可 //创建数据库文件 SQLiteConnection.CreateFile("sqlitetest.db" ...

  2. 3、MapReduce

    MapReduce是一种处理海量数据的并行编程模型和计算框架,用于对大数据及的并行计算. 1.MapReduce基础 1)MapReduce处理数据集过程,如下图: a)Map阶段: MapReduc ...

  3. WPF从入门到放弃系列第一章 初识WPF

    什么是WPF WPF(Windows Presentation Foundation)是微软推出的基于Windows Vista的用户界面框架,属于.NET Framework 3.0的一部分.它提供 ...

  4. repo manifest xml 文件修改后提交命令

    git push origin dev(本地分支):refs/for/tv/Internal_Jb910_develop_t

  5. 关于hibernate的实体类中有集合类型转化成JSON的工具类 - 怀念今天的专栏 - 博客频道

    Json 来源:http://blog.csdn.net/zczzsq/article/details/18697045#1536434-hi-1-4387-42d97150898b1af15ddaa ...

  6. location.hash && location.href

    hash:设置或获取 href 属性中在井号“#”后面的分段. href:设置或获取整个URL为字符串. 通过下面的测试你会发现区别,将代码放到你的HTML中,然后用浏览器打开,测试步骤: 点击“超链 ...

  7. 网上测试了很多关于PYTHON的WEBSOCKET样例,下面这个才成功了

    这是最底层的, 嘿嘿,我 还是习惯搞个框架来实现急需要的功能... 这个东东玩得很有意思的.. 服务器端的代码: import simplejson import socket import sys ...

  8. Altium Designer学习: 原理图和PCB元件对应查找

    画PCB的时候,需要经常的去查看原理图上对应的元件,元件数目少还好找,数目多了找起来就比较扯淡.还要Altium Designer提供了不错的交叉查找功能. 这里我建议使用两个显示器,一个显示器放原理 ...

  9. More on 1Password’s Components

    Stefan van As of 1Password fame sent me a more exhaustive list of the libraries and tools used in 1P ...

  10. Android 去除list集合中重复项的几种方法

    因为用到list,要去除重复数据,尝试了几种方法.记录于此... 测试数据: List<"}; List<string> li2 = new List<string& ...