bzoj 1022 小约翰的游戏John
题目大意:
n堆石子,两个人轮流取石子,每个人取的时候,可以随意选择一堆石子
在这堆石子中取走任意多的石子,但不能一粒石子也不取,取到最后一粒石子的人算输
思路:
首先当每堆石子数都为1时,偶数为先手必胜,奇数为先手必败
当有一堆石子数不为1时,先手可以使堆变为奇数个1的堆,即先手必胜
而如果有很多堆石子数不为1,如果异或和不为0,则先手可以把异或和变为0 变为必胜态
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<map>
#include<vector>
#define ll long long
#define inf 2147483611
#define MAXN 1010
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-;ch=getchar();}
while(isdigit(ch)) {x=x*+ch-'';ch=getchar();}
return x*f;
}
int T,n;
int main()
{
T=read();int sum,a;bool f;
while(T--)
{
n=read(),sum=f=;
for(int i=;i<=n;i++)
{
a=read();
sum^=a;
if(a!=) f=;
}
if((!f&&!sum)||(sum&&f)) puts("John");
else puts("Brother");
}
}
bzoj 1022 小约翰的游戏John的更多相关文章
- BZOJ 1022 小约翰的游戏
Description 小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有n堆石子,小约翰和他的哥哥轮流取石子,每个人取的时候,可以随意选择一堆石子,在这堆石子中取走任意多的石子,但不能一粒石子也不取 ...
- BZOJ 1022 小约翰的游戏 (Anti-Nim游戏)
题解:注意题目中规定取到最后一粒石子的人算输,所以是Anti-Nim游戏,胜负判断为: 先手必胜: 1.所有堆的石子数都为1且游戏的SG值为0: 2.有些堆的石子数大于1且游戏的SG值不为0. #in ...
- BZOJ 1022 小约翰的游戏(anti-sg)
这是个anti-sg问题,套用sj定理即可解. SJ定理 对于任意一个Anti-SG游戏,如果定义所有子游戏的SG值为0时游戏结束,先手必胜的条件: 1.游戏的SG值为0且所有子游戏SG值均不超过1. ...
- bzoj 1022: [SHOI2008]小约翰的游戏John anti_nim游戏
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1189 Solved: 734[Submit][ ...
- BZOJ 1022 [SHOI2008]小约翰的游戏John
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1635 Solved: 1036[Submit] ...
- BZOJ 1022 [SHOI2008]小约翰的游戏John AntiNim游戏
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1475 Solved: 932[Submit][ ...
- 1022: [SHOI2008]小约翰的游戏John
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1322 Solved: 829[Submit][ ...
- 1022: [SHOI2008]小约翰的游戏John【Nim博弈,新生必做的水题】
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2709 Solved: 1726[Submit] ...
- bzoj千题计划112:bzoj1022: [SHOI2008]小约翰的游戏John
http://www.lydsy.com/JudgeOnline/problem.php?id=1022 http://www.cnblogs.com/TheRoadToTheGold/p/67448 ...
随机推荐
- Vue指令2:v-bind
v-bind 指令可以更新 HTML 属性: <a v-bind:href="url">...</a> 在这里 href 是参数,告知 v-bind 指令将 ...
- 02Oracle Database 安装,卸载,系统服务,系统组件及系统表空间
Oracle Database 安装,卸载,系统服务,系统组件及系统表空间 Oracle Database 安装 Oracle Database 卸载 Oracle Database 系统服务 Ora ...
- 这段代码很Pythonic | 相见恨晚的 itertools 库
前言 最近事情不是很多,想写一些技术文章分享给大家,同时也对自己一段时间来碎片化接受的知识进行一下梳理,所谓写清楚才能说清楚,说清楚才能想清楚,就是这个道理了. 很多人都致力于把Python代码写得更 ...
- 牛客多校Round 6
Solved:3 rank:156 J. Heritage of skywalker 学习一下nth_element 可以o (n)的找出前多少大的元素 #include <bits/stdc+ ...
- spring boot+mybatis+mysql增删改查分页
server: port: servlet: context-path: /springBootMybatis spring: datasource: name: test url: jdbc:mys ...
- NFS文件服务
安装NFS服务 Yum install nfs-utils –y 2.关闭防火墙 service iptables stop 3./etc/exports NFS服务配置文件 /home/share ...
- php正则表达式匹配html标签
用php正则表达式找出div标签,div允许多层嵌套,比如在以下文本中找出class为quizPutTag的div? <html> <head></head> &l ...
- springcloud(十):熔断监控Hystrix Dashboard
申明: 这里比较坑爹,大家写的时候要小心,这里和springboot的版本有关系哈,我使用的是2.0 版本,要么调频为1.5 版本,要么使用其他方式 解决错误,我选择了还是用2.0 ...
- Codeforces 263A. Appleman and Easy Task
A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input ...
- hdu 2647拓扑排序 结构体模拟容器
#include<stdio.h> #include<queue> #include<iostream> using namespace std; #define ...