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. ...
随机推荐
- 594. Longest Harmonious Subsequence强制差距为1的最长连续
[抄题]: We define a harmonious array is an array where the difference between its maximum value and it ...
- NanoPi2
https://item.taobao.com/item.htm?spm=a230r.1.14.9.Ijhc8S&id=526981593477&ns=1&abbucket=1 ...
- bootstrap三列布局
<!DOCTYPE html><html lang="zh-cn"><head><meta charset="utf-8&quo ...
- IIS 身份验证
IIS 支持以下身份验证模式: 匿名.如果不需要对客户端进行身份验证(或者使用自定义身份验证机制,如窗体身份验证),则可将 IIS 配置为允许匿名访问.在该事件中,IIS 创建一个 Windows 令 ...
- 图的遍历——DFS
原创 图的遍历有DFS和BFS两种,现选用DFS遍历图. 存储图用邻接矩阵,图有v个顶点,e条边,邻接矩阵就是一个VxV的矩阵: 若顶点1和顶点5之间有连线,则矩阵元素[1,5]置1,若是无向图[5, ...
- hibernate的获取session的两方法比较,和通过id获取对象的比较,一级缓存二级缓存
opensession与currentsession的联系与区别 在同一个线程中opensession的session是不一样的,而currentsession获取的session是一样的,这就保证了 ...
- js任意位数求和
<script> //任意位数求和 function sum(){ if(arguments.length==1) { console.log(arguments[0]) return; ...
- HTML <area> 标签区域map标签
1.距形:(左上角顶点坐标为(x1,y1),右下角顶点坐标为(x2,y2)) <area shape="rect" coords="x1,y1,x2,y2" ...
- 【转】Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/18234477 本篇文章主要内容来自于Android Doc,我翻译之后又做了些加工 ...
- SQL 2005报错之Restore fail for Server 'DatabaseServerName'.
Restore fail for Server 'DatabaseServerName'.(Microsoft.SqlServer.Smo) Additional information: Syste ...