HDU - 1907 anti-SG
题意:nim游戏,最后取光为【输】
anti-SG的应用,搬运一下我的摸鱼小笔记
最先看到的应该是分奇偶的非充裕堆判断,若为偶数则先手胜,否则后手胜
按SG分类
SG!=0时
1.只有一堆大于1,先手可以把这堆化为0或者1,然后从上面的结果来看,先手必胜
2.大于一堆大于1,先手可以把SG=0的局面留给对手,先手必胜
3.没有一堆大于1,那就是只有奇数个非充裕堆的情况,先手必败
SG=0时
1.只有一堆大于1,不存在此情况
2.大于一堆大于1,先手无论如何操作,对于后手的局面总有大于一堆大于1,且后手SG!=0,从上面讨论的结果来看,先手必败
3.没有一堆大于1,既只有偶数个非充裕堆的情况,先手必胜
这个过程比较麻烦,要学会利用结论
结论:
单一SG=0时子游戏结束,先手必胜的条件需满足
1.SG!=0且存在单一SG>1
2.SG=0且所有单一SG<=1
那刚才的anti-nim游戏就分别对应于
1.SG!=0且至少一堆大于1
2.SG=0且所有堆为1
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e6+11;
const int oo = 0x3f3f3f3f;
const double eps = 1e-7;
typedef long long ll;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){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=read();
while(T--){
int n=read();
ll t=0,cnt=0,cnt2=0;
rep(i,1,n){
ll x=read();
t^=x;
if(x==1) cnt++;
else cnt2++;
}
if(t!=0&&cnt2>=1) printf("John\n");
else if(t==0&&(cnt==n)&&(cnt%2==0)) printf("John\n");
else printf("Brother\n");
}
return 0;
}
HDU - 1907 anti-SG的更多相关文章
- HDU 1907 Nim博弈变形
1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
- hdu 1907 John (anti—Nim)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)http://acm.h ...
- hdu 1907 John(anti nim)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- hdu 1404 找sg ***
HDU 1404 Digital Deletions 一串由0~9组成的数字,可以进行两个操作:1.把其中一个数变为比它小的数:2.把其中一个数字0及其右边的所以数字删除. 两人轮流进行操作,最后把 ...
- hdu 1848 简单SG函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...
- hdu 1907 (尼姆博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very ...
- POJ 3480 & HDU 1907 John(尼姆博弈变形)
题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Descri ...
- HDU 4678 Mine SG博弈
http://acm.hdu.edu.cn/showproblem.php?pid=4678 自己太蠢...没学SG...还是浩神指点我SG精髓以后才A的这题...(第一题SG 这里子游戏之间没有影响 ...
- HDU 5742 Chess SG函数博弈
Chess Problem Description Alice and Bob are playing a special chess game on an n × 20 chessboard. ...
随机推荐
- BeautifulSoup练习
html1="""<!DOCTYPE html><html lang="en" xmlns="http://www.w3. ...
- ubuntu PCL的使用
cmake_minimum_required(VERSION 2.8) project(MY_GRAND_PROJECT) find_package(PCL 1.3 REQUIRED COMPONEN ...
- osm2pgsql导入少字段
Explanation: osm2pgsql imports normally the data in a static database schema. The tags without a cor ...
- spark源码阅读之network(2)
在上节的解读中发现spark的源码中大量使用netty的buffer部分的api,该节将看到netty核心的一些api,比如channel: 在Netty里,Channel是通讯的载体(网络套接字或组 ...
- hdu 1556 Color the ball (线段树做法)
Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a ...
- JSP内置对象与servlet对应关系
隐式对象 说明 out 转译后对应JspWriter对象,其内部关联一个PringWriter对象 request 转译后对应HttpServletRequest/ServletRequest对象 r ...
- 字符串的查找删除---C++中string.find()函数与string::npos
给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串 输入: 输入只有一组数据 输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止 输出: 删除输入的短字符串 ...
- 基于CentOS6定制自己的ISO安装光盘
警告:转载请注明出处 https://www.cnblogs.com/BoyTNT/p/9322927.html 1.目标 >> 基于CentOS-6.10-x86_64-minimal ...
- 安卓开发时访问google方法
启动浏览器后15秒左右,浏览器的右上角就会出现图标 启用防火墙功能(右上角墙形图标),这时候程序就会去寻找网上代理,从而达到访问GOOGLE的效果,提示如果不访问google网站,可再点击一下关闭防火 ...
- 用C语言构建一个可执行程序的流程
1.流程图 从用C语言写源代码,然后经过编译器.连接器到最终可执行程序的流程图大致如下图所示. 2.编译流程 首先,我们先用C语言把源代码写好,然后交给C语言编译器.C语言编译器内部分为前端和后端. ...