思路: 注意与Nimm博弈的区别,谁拿完谁输!

先手必胜的条件:

1.  每一个小游戏都只剩一个石子了,且SG = 0.

2. 至少有一堆石子数大于1,且SG不等于0

证明:1. 你和对手都只有一种选择,随便怎么拿,你都赢了

2.  a:如果只有一堆石子数量大于1,那么你赢了,你可以拿完使得整个游戏的1的数量不变,剩余1个整个游戏1的数量增加。

b:如果至少有两堆石子数大于1,那么你可以让SG变为0,令对手处于P态,并且当前至少有两堆数量大于1,对手无论怎么拿SG都会变成非0.

结论:当石子数量全为1时,且SG=1必输,当石子数有大于两堆的石子数量大于2,且SG!=0,必输,其他情况都是必赢。

AC代码

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 1e4 + 5;
void in(int &a) {
	char ch;
	while((ch=getchar()) < '0' || ch >'9');
	for(a = 0; ch >= '0' && ch <= '9'; ch = getchar()) {
		a = a * 10 + ch - '0';
	}
}

int main() {
	int T, n;
	scanf("%d", &T);
	while(T--) {
		in(n);
		int res = 0, x, cnt = 0;
		for(int i = 0; i < n; ++i) {
			in(x);
			res ^= x;
			if(x > 1) ++cnt;
		}
		if(cnt == 0 && res || !res && cnt >= 2) printf("Brother\n");
		else printf("John\n");
	}
	return 0;
}

如有不当之处欢迎指出!

HDU - 1907 John 反Nimm博弈的更多相关文章

  1. HDU 1907 John (Nim博弈)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  2. hdu 1907 John (尼姆博弈)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  3. nyoj888 取石子(九) 反Nimm博弈

    这题就是反Nimm博弈--分析见反Nimm博弈 AC代码 #include <cstdio> #include <cmath> #include <algorithm&g ...

  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&& hdu 2509 Be the Winner(基础nim博弈)

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

  6. HDU 1907 John(博弈)

    题目 参考了博客:http://blog.csdn.net/akof1314/article/details/4447709 //0 1 -2 //1 1 -1 //0 2 -1 //1 2 -1 / ...

  7. HDU 1907 John nim博弈变形

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

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

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

  9. hdu 1907 (尼姆博弈)

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

随机推荐

  1. Sql Server的艺术(二) SQL复杂条件搜索

    本次讲到where字句中经常用到的集中较为复杂的搜索条件,包括组合的查询条件.IN运算符.NOT运算符.LIKE运算符和相关通配符. 学习本节需要用到一下两张表: CREATE TABLE TEACH ...

  2. 高仿bootstrap样式的分页插件

    链接:https://pan.baidu.com/s/1jKgn2hK 密码:whwl 不知道是自己的第几个分页插件了,以前写一个丢一个,桌面,U盘,移动硬盘.想用的时候找不到,这次传网上来.大家帮忙 ...

  3. Oracle Rac创建表空间及用户

    1. 创建表空间: BEGIN DECLARE cnt integer := 0; BEGIN SELECT 1 INTO cnt FROM dual WHERE exists(SELECT * FR ...

  4. MySQL用户授权与权限

    MySQL权限如下表 权限名字 权限说明 Context CREATE 允许创建新的数据库和表 Databases, tables, or indexes DROP 允许删除现有数据库.表和视图 Da ...

  5. Spring整合JMS(四)——事务管理

    原文链接:http://haohaoxuexi.iteye.com/blog/1983532 Spring提供了一个JmsTransactionManager用于对JMS ConnectionFact ...

  6. 洛谷 [P3258] 松鼠的新家

    树上差分 对于一条路径 \(u->v\) 来说,设 \(t=LCA(u,v)\) ,d[]为差分数组 ,则有 d[u]++;d[v]++;d[t]--;d[fa[t]]--; 注意:题目中所给的 ...

  7. BZOJ 3731 3731: Gty的超级妹子树 [树上size分块 !]

    传送门 题意:一棵树,询问子树中权值大于k的节点个数,修改点权值,插入新点,断开边:强制在线 该死该死该死!!!!!! MD我想早睡觉你知不知道 该死该死沙比提 断开边只会影响一个块,重构这个块就行了 ...

  8. 试着把.net的GC讲清楚(1)

    什么是GC? GC(garbage collection)是对内存管理中回收已经不用的内存的一种机制,我们熟知的java和.net都有自己的GC机制,是内存管理的一部分. 为什么会有GC呢?是因为动态 ...

  9. 反反爬虫 IP代理

    0x01 前言 一般而言,抓取稍微正规一点的网站,都会有反爬虫的制约.反爬虫主要有以下几种方式: 通过UA判断.这是最低级的判断,一般反爬虫不会用这个做唯一判断,因为反反爬虫非常容易,直接随机UA即可 ...

  10. [Python Study Notes] Python的安装

    Windows: 1.下载安装包: 转到Python官网https://www.python.org/downloads/  ,下载最新版本的Python. 2.安装 安装到自定义的安装路径下. 3. ...