思路: 注意与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. Markdown中使用mermaid画流程图

    Markown语法简单,用来写文档是个不错的选择. 但是Markdown 语法并不直接支持画图,当然方法还是有的. 本人用的Markdown编辑器为vscode,在里面直接安装merdaid插件即可使 ...

  2. hibernate 持久化对象的三个状态

    Hibernate中的对象有3种状态 瞬时对象(TransientObjects).持久化对象(PersistentObjects)和离线对象(DetachedObjects也叫做脱管对象) Tran ...

  3. EL表达式和JSTL核心标签库

    1 EL表达式 1.1 EL的概述 EL,全名为Expression Language. 主要作用: ①EL表达式主要用于替换jsp页面中的脚本表达式,以便于从各种类型的web域中检索java对象(某 ...

  4. java IO(二):字节流

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...

  5. c# 基础任务1

    1.winform系统全局异常布局处理. Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);   ...

  6. windows 7 wifi热点配置

    自我总结,有什么不足或更好的解决方案,请告知,感激不尽! 目的:闲来无事的童鞋,可以试一试自己配置wifi热点. ps:其实wifi热点配置是系统存在的功能,只不过需要配置. 现在win桌面wifi热 ...

  7. git的sshkey生成步骤

    找到git安装的目录,运行"git-bash.exe". 配置git的user的name及email $ git config --global user.name "u ...

  8. 解决mysql、vsftp远程连接速度慢的问题

    以 centOS 6.3(其他操作系统类似,同样适用)说明: 当我们的服务都配置正常的情况下,有时会出现连接速度慢而导致连接失败的问题 问题分析:这些情况一般都是DNS解析惹的祸 mysql连接速度慢 ...

  9. SpringBoot学习之Json数据交互

    最近在弄监控主机项目,对javaweb又再努力学习.实际的项目场景中,前后分离几乎是所以项目的标配,全栈的时代的逐渐远去,后端负责业务逻辑处理,前端负责数据展示成了一种固定的开发模式.像thymele ...

  10. Redis进阶实践之十一 Redis的Cluster集群搭建

    一.引言      本文档只对Redis的Cluster集群做简单的介绍,并没有对分布式系统的详细概念做深入的探讨.本文只是提供了有关如何设置集群.测试和操作集群的说明,而不涉及Redis集群规范中涵 ...