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. ...
随机推荐
- golang hello
package main import "fmt" func main() { fmt.Printf("Hello, world.\n") }
- c语言学习笔记 多级else if 和switch case有什么区别
; ) { dosth(); } ) { dosth2(); } else if(opion==) { dosth3(); } else dosth4(); 如果给option的一个值是2的话,那么程 ...
- 19. AUTO INCREMENT 字段
Auto-increment 会在新记录插入表中时生成一个唯一的数字. AUTO INCREMENT 字段 我们通常希望在每次插入新记录时,自动地创建主键字段的值. 我们可以在表中创建一个 auto- ...
- IntelliJ IDEA——利用maven插件构建web工程
- sql server行列转化
行列转换: 姓名 课程 分数 张三 语文 74 张三 数学 83 张三 物理 93 李四 语文 74 李四 数学 84 李四 物理 94 想变成(得到如下结果): 姓名 语文 数学 物理 ---- - ...
- LibreOJ 6003 魔术球 (最大流)
题解:每次加入两个点,对于和为平方数的两个值所对应的点建边,反正网络流可以跑残量网络,所以就没有什么关系了…… 代码如下: #include<cmath> #include<queu ...
- <%@ include > 与< jsp:include >
include指令表示在JSP编译时插入一个包含文本或者代码的文件,把文件中的文本静态地包含过去.也就是说,会把被包含的页面拷贝到包含的页面中指令所在的位置. 语法格式:<%@ include ...
- TSQL--时间类型和毫秒数转换
项目中使用BIGINT来存放时间,以下代码用来转换时间类型和BIGINT类型 SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ========= ...
- ASP.NET MVC Controller 编程所涉及到的常用属性成员
Controller (System.Web.Mvc.Controller) 1.获取路由中的各个值 Request.RequestContext.RouteData.Values["id& ...
- angular学习文章
https://www.jianshu.com/p/86c6249a2069 angular.cn https://segmentfault.com/a/1190000008754631