题目

不会,抄论文

这是一个非常牛逼的东西,叫做\(anti\)博弈,就是进行最后一次操作的人输

我们考虑一下这道题

显然如果石子个数都是\(1\),那么有奇数堆石子先手必败,有偶数堆石子先手必胜

如果只有一堆石子大于\(1\),如果当前是奇数堆石子,那么我们可以把这堆石子取到只剩下一个,如果是偶数堆石子,我们直接把大于\(1\)的这一堆都拿走,这样我们就能让对方面对必败局面

考虑刚才的局面的\(SG\)函数值,显然不为\(0\)

而我们发现随着游戏的进行石子的减少,刚才的局面一定会出现

所以只要\(SG\)函数不为\(0\)且不是最开始的那种全是\(1\)的情况就能判定先手必胜了

因此我们得到了针对\(anti-SG\)的\(SJ\)定理

对于一个\(anti-SG\)游戏先手必胜的条件为满足下两个条件之一

  1. \(SG\)函数大于\(0\),且有至少一个单个游戏的\(SG\)函数大于\(1\)

  2. \(SG\)函数等于\(0\),且没有任何一个单个游戏的\(SG\)函数大于\(1\)

代码

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
int T,a,n;
int main() {
T=read();
while(T--) {
n=read();int tot=0,s=0;
for(re int i=1;i<=n;i++)
a=read(),tot+=(a==1),s^=a;
if(tot==n) puts(s?"Brother":"John");
else puts(s?"John":"Brother");
}
return 0;
}
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
int T,a,n;
int main() {
T=read();
while(T--) {
n=read();int tot=0,s=0;
for(re int i=1;i<=n;i++)
a=read(),tot+=(a==1),s^=a;
if(tot==n) puts(s?"Brother":"John");
else puts(s?"John":"Brother");
}
return 0;
}

[SHOI2008]小约翰的游戏的更多相关文章

  1. SHOI2008小约翰的游戏John

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1139  Solved: 701[Submit][ ...

  2. bzoj 1022: [SHOI2008]小约翰的游戏John anti_nim游戏

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1189  Solved: 734[Submit][ ...

  3. BZOJ 1022 [SHOI2008]小约翰的游戏John

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1635  Solved: 1036[Submit] ...

  4. 1022: [SHOI2008]小约翰的游戏John

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1322  Solved: 829[Submit][ ...

  5. 1022: [SHOI2008]小约翰的游戏John【Nim博弈,新生必做的水题】

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2709  Solved: 1726[Submit] ...

  6. 洛谷 P4279 [SHOI2008]小约翰的游戏 解题报告

    P4279 [SHOI2008]小约翰的游戏 题目描述 小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有\(n\)堆石子,小约翰和他的哥哥轮流取石子,每个人取的时候,可以随意选择一堆石子,在这堆石子 ...

  7. bzoj千题计划112:bzoj1022: [SHOI2008]小约翰的游戏John

    http://www.lydsy.com/JudgeOnline/problem.php?id=1022 http://www.cnblogs.com/TheRoadToTheGold/p/67448 ...

  8. BZOJ 1022 [SHOI2008]小约翰的游戏John AntiNim游戏

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1475  Solved: 932[Submit][ ...

  9. BZOJ1022 [SHOI2008]小约翰的游戏John 【博弈论】

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MB Submit: 3014  Solved: 1914 [Submi ...

  10. 1022: [SHOI2008]小约翰的游戏John9(Auti_SG)

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 3150  Solved: 2013[Submit] ...

随机推荐

  1. [javaSE] 类型转换(1加1等于几)

    打印 ‘a’+1,输出98,解释:’a’是char类型占2个8bit,1是int类型占4个,’a’字符会被自动强制转换为int类型对应ascii码表97 打印’1’+1,输出 50,解释:’1’是ch ...

  2. XCode 添加自定义framework运行时出现dyld: Library not loaded的解决方法

    XCode添加自定义framework运行时出现dyld: Library not loaded的解决方法 在使用自定义的framework运行时,会出现如下的错误: dyld: Library no ...

  3. 高并发第十单:J.U.C AQS(AbstractQueuedSynchronizer) 组件:CountDownLatch. CyclicBarrier .Semaphore

    这里有一篇介绍AQS的文章 非常好: Java并发之AQS详解 AQS全名:AbstractQueuedSynchronizer,是并发容器J.U.C(java.lang.concurrent)下lo ...

  4. Go 语言实现 HTTP 层面的反向代理

    最近对 Go 语言的反向代理使用得偏多,其实在大概两年前就写过 TCP 层面的代理,而且那时也是用的 Go 语言,不同之处在于之前只是偶尔尝试一下使用,最近是因为工作需要使用的.相比较于 TCP 层面 ...

  5. BZOJ2227 [Zjoi2011]看电影(movie)

    Description \(k\)个座位,\(n\)个人依次过来,每人随机从\(k\)个座位中选择一个,并从它开始不停向后走直到遇到空座位坐下.求所有人都能坐下的概率(即没有人走到第\(k+1\)个位 ...

  6. Keras vs. PyTorch in Transfer Learning

    We perform image classification, one of the computer vision tasks deep learning shines at. As traini ...

  7. ARCGIS知乎上的好文章

    http://zhihu.esrichina.com.cn/?/feature/ArcGISAndroidDevNote ArcGIS知乎上有哪些干货可以推荐? http://zhihu.esrich ...

  8. java实现Kafka的消费者示例

    使用java实现Kafka的消费者 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3 ...

  9. ExtJs 4.1.1 文件结构解析

  10. canvas动画部分

    requestAnimationFrame(callback) 一个用于制作逐帧动画的函数 //这个函数会在控制台无限输出"----" (function animate() { ...