博弈入门题吧。

把尼姆博弈推广到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. 解决php json_encode 出现的中文转码、乱码问题

    // 防止json中文转码 function jsonEncodeWithCN($data) { return preg_replace("/\\\u([0-9a-f]{4})/ie&quo ...

  2. Android LruCache究竟是什么

    源码: /frameworks/base/core/java/android/util/LruCache.java 文件开篇注释如下: A cache that holds strong refere ...

  3. ZeroMQ/jzmq安装使用

    环境: No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 12.04.2 LTS Release: 12 ...

  4. HBASE的安装

    HBASE的安装: 安装的软件版本:hbase-0.98.4-hadoop2.tar.gz 下载链接:http://www.apache.org/dist/hbase/hbase-0.98.4/ 1. ...

  5. Oracle job procedure

    Oracle job procedure 存储过程定时任务 oracle job有定时执行的功能,可以在指定的时间点或每天的某个时间点自行执行任务. 一.查询系统中的job,可以查询视图 --相关视图 ...

  6. Quartz Sheduler 入门

    Quartz Sheduler 入门 原文地址:http://www.quartz-scheduler.org/generated/2.2.2/html/qtz-all/ 下载地址:http://qu ...

  7. ACM-进阶之路

    ACM进阶计划 ACM队不是为了一场比赛而存在的,为的是队员的整体提高. 大学期间,ACM队队员必须要学好的课程有: l C/C++两种语言 l 高等数学 l 线性代数 l 数据结构 l 离散数学 l ...

  8. single page

    http://msdn.microsoft.com/zh-cn/magazine/cc507641.aspx#S7 http://blog.nodejitsu.com/scaling-isomorph ...

  9. No Pain No Game

    hdu4630:http://acm.hdu.edu.cn/showproblem.php?pid=4630 题意:给定一个排序,求区间最大GCD. 题解:离散树状数组.首先把查询按左端点从大到小排序 ...

  10. ***PHP 去除换行符

    PHP在不同的系统中,换行是不同的 Linux:\n Windows:\r\n mac:\r 所以去除回车换行的方法: 1.使用php定义好的变量(比较好的方法,推荐) $str= str_repla ...