luoguP4279 [SHOI2008]小约翰的游戏 Anti-SG 博弈论

这就是一个Anti SG问题
当整个游戏的\(sg = 0\)时,如果不存在单一游戏局面\(sg > 1\),那么先手必胜
当整个游戏的\(sg \neq 0\)时,如果至少存在一个单一游戏局面\(sg > 1\),那么先手必胜
简略的证一下QAQ
首先证\(N\)至少有一个后继是\(P\)
- 整个游戏的\(sg = 0\),不存在单一游戏局面\(sg > 1\)
一定有偶数个\(1\),显然先手必胜
- 整个游戏的\(sg \neq 0\),至少存在一个单一游戏局面\(sg > 1\)
类似\(Nim\)游戏,先手一定可以选出一堆石头使得\(sg = 0\)
然后是\(P\)的后继全部都是\(N\)
- 整个游戏的\(sg \neq 0\),不存在单一游戏局面\(sg > 1\)
一定有奇数个\(1\),显然先手必败
- 整个游戏的\(sg = 0\),至少存在一个单一游戏局面\(sg > 1\)
由于\(sg = 0\),因此一定存在两个以上的单一游戏局面\(sg > 1\)
此时,不论先手怎么取,后继状态的\(sg\)不可能等于\(0\),并且至少存在一个单一游戏局面\(sg > 1\)
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
#define ri register int
#define rep(io, st, ed) for(ri io = st; io <= ed; io ++)
#define drep(io, ed, st) for(ri io = ed; io >= st; io --)
#define gc getchar
inline int read() {
int p = 0, w = 1; char c = gc();
while(c < '0' || c > '9') { if(c == '-') w = -1; c = gc(); }
while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();
return p * w;
}
int a[50050];
int main() {
int T = read();
while(T --) {
int n = read();
rep(i, 1, n) a[i] = read();
int flag = 0, sg = 0, win;
rep(i, 1, n) flag += (a[i] > 1), sg ^= a[i];
if(!flag && sg == 0) win = 1;
else if(flag && sg != 0) win = 1;
else win = 0;
if(win == 1) printf("John\n");
else printf("Brother\n");
}
return 0;
}
luoguP4279 [SHOI2008]小约翰的游戏 Anti-SG 博弈论的更多相关文章
- BZOJ1022 [SHOI2008]小约翰的游戏John 【博弈论】
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MB Submit: 3014 Solved: 1914 [Submi ...
- [Bzoj1022][SHOI2008]小约翰的游戏John(博弈论)
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2976 Solved: 1894[Submit] ...
- 【BZOJ】1022: [SHOI2008]小约翰的游戏John(博弈论)
http://www.lydsy.com/JudgeOnline/problem.php?id=1022 好神的博弈论. 题解见dzy的blog:http://dzy493941464.is-prog ...
- SHOI2008小约翰的游戏John
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1139 Solved: 701[Submit][ ...
- bzoj 1022: [SHOI2008]小约翰的游戏John anti_nim游戏
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1189 Solved: 734[Submit][ ...
- 洛谷 P4279 [SHOI2008]小约翰的游戏 解题报告
P4279 [SHOI2008]小约翰的游戏 题目描述 小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有\(n\)堆石子,小约翰和他的哥哥轮流取石子,每个人取的时候,可以随意选择一堆石子,在这堆石子 ...
- BZOJ 1022 [SHOI2008]小约翰的游戏John AntiNim游戏
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1475 Solved: 932[Submit][ ...
- 1022: [SHOI2008]小约翰的游戏John9(Auti_SG)
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 3150 Solved: 2013[Submit] ...
- BZOJ 1022 [SHOI2008]小约翰的游戏John
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1635 Solved: 1036[Submit] ...
随机推荐
- [转]CMake快速入门教程:实战
转自http://blog.csdn.net/ljt20061908/article/details/11736713 0. 前言 一个多月前,由于工程项目的需要,匆匆的学习了一下cmake的使 ...
- Wannacry样本取证特征与清除
一.取证特征 1)网络域名特征 http://www.iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com 2)文件特征 母体文件 mssecsvc.exe c: ...
- CentOS时区GMT修改为CST
GMT:格林尼标准时间 北京时间=GMT时间+8小时 [root@sa~]# date -R 查看目前服务器的时间标准 [root@sa~]# vi /etc/sysconfig/clock 将ZON ...
- innobackupex 相关语法讲解【转】
innobackupex 相关语法讲解 连接服务器 The database user used to connect to the server and its password are speci ...
- 查看linux服务器内存信息
查看服务器内存信息 dmidecode|grep -P -A5 "Memory\s+Device"|grep Size [root@localhost home]# dmideco ...
- asp.net 伪静态实现(UrlRewritingNet)
UrlRewritingNet.UrlRewriter源码地址 https://github.com/aspnetde/UrlRewritingNet部署步骤: 步骤一: <!--只允许存在一个 ...
- c# CTS 基础数据类型笔记
C#中的基础数据类型并没有内置于c#语言中,而内置于.net freamework. C#有15个预定义类型,其中13个是值类型,两个是引用类型(string和object) 一.值类型 值类型 数据 ...
- hibernate的枚举注解@Enumerated
@Enumerated(value=EnumType.ORDINAL)采用枚举类型的序号值与数据库进行交互, 此时数据库的数据类型需要是数值类型,例如在实际操作中 CatTest ct = new C ...
- linux cpu、内存、硬盘空间查询
[CPU] 算式: CPU总核数 = 物理CPU个数 * 每颗物理CPU的核数 总逻辑CPU数 = 物理CPU个数 * 每颗物理CPU的核数 * 超线程数 #查看CPU型号 cat /proc/cpu ...
- 数据库-mysql中文显示问题
一:在mysql 下面查看带中文的记录显示乱码 mysql> select * from role; +----+------+ | id | name | +----+------+ | 1 ...