题意: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

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<cstdlib>
  6. #include<cmath>
  7. #include<string>
  8. #include<vector>
  9. #include<stack>
  10. #include<queue>
  11. #include<set>
  12. #include<map>
  13. #define rep(i,j,k) for(register int i=j;i<=k;i++)
  14. #define rrep(i,j,k) for(register int i=j;i>=k;i--)
  15. #define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
  16. #define iin(a) scanf("%d",&a)
  17. #define lin(a) scanf("%lld",&a)
  18. #define din(a) scanf("%lf",&a)
  19. #define s0(a) scanf("%s",a)
  20. #define s1(a) scanf("%s",a+1)
  21. #define print(a) printf("%lld",(ll)a)
  22. #define enter putchar('\n')
  23. #define blank putchar(' ')
  24. #define println(a) printf("%lld\n",(ll)a)
  25. #define IOS ios::sync_with_stdio(0)
  26. using namespace std;
  27. const int maxn = 1e6+11;
  28. const int oo = 0x3f3f3f3f;
  29. const double eps = 1e-7;
  30. typedef long long ll;
  31. ll read(){
  32. ll x=0,f=1;register char ch=getchar();
  33. while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  34. while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  35. return x*f;
  36. }
  37. int main(){
  38. int T=read();
  39. while(T--){
  40. int n=read();
  41. ll t=0,cnt=0,cnt2=0;
  42. rep(i,1,n){
  43. ll x=read();
  44. t^=x;
  45. if(x==1) cnt++;
  46. else cnt2++;
  47. }
  48. if(t!=0&&cnt2>=1) printf("John\n");
  49. else if(t==0&&(cnt==n)&&(cnt%2==0)) printf("John\n");
  50. else printf("Brother\n");
  51. }
  52. return 0;
  53. }

HDU - 1907 anti-SG的更多相关文章

  1. HDU 1907 Nim博弈变形

    1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...

  2. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

  3. hdu 1907 John (anti—Nim)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)http://acm.h ...

  4. hdu 1907 John(anti nim)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  5. hdu 1404 找sg ***

    HDU 1404  Digital Deletions 一串由0~9组成的数字,可以进行两个操作:1.把其中一个数变为比它小的数:2.把其中一个数字0及其右边的所以数字删除. 两人轮流进行操作,最后把 ...

  6. hdu 1848 简单SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...

  7. hdu 1907 (尼姆博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very ...

  8. POJ 3480 &amp; HDU 1907 John(尼姆博弈变形)

    题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Descri ...

  9. HDU 4678 Mine SG博弈

    http://acm.hdu.edu.cn/showproblem.php?pid=4678 自己太蠢...没学SG...还是浩神指点我SG精髓以后才A的这题...(第一题SG 这里子游戏之间没有影响 ...

  10. HDU 5742 Chess SG函数博弈

    Chess Problem Description   Alice and Bob are playing a special chess game on an n × 20 chessboard. ...

随机推荐

  1. BeautifulSoup练习

    html1="""<!DOCTYPE html><html lang="en" xmlns="http://www.w3. ...

  2. ubuntu PCL的使用

    cmake_minimum_required(VERSION 2.8) project(MY_GRAND_PROJECT) find_package(PCL 1.3 REQUIRED COMPONEN ...

  3. osm2pgsql导入少字段

    Explanation: osm2pgsql imports normally the data in a static database schema. The tags without a cor ...

  4. spark源码阅读之network(2)

    在上节的解读中发现spark的源码中大量使用netty的buffer部分的api,该节将看到netty核心的一些api,比如channel: 在Netty里,Channel是通讯的载体(网络套接字或组 ...

  5. hdu 1556 Color the ball (线段树做法)

    Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a ...

  6. JSP内置对象与servlet对应关系

    隐式对象 说明 out 转译后对应JspWriter对象,其内部关联一个PringWriter对象 request 转译后对应HttpServletRequest/ServletRequest对象 r ...

  7. 字符串的查找删除---C++中string.find()函数与string::npos

    给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串 输入: 输入只有一组数据 输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止 输出: 删除输入的短字符串 ...

  8. 基于CentOS6定制自己的ISO安装光盘

    警告:转载请注明出处 https://www.cnblogs.com/BoyTNT/p/9322927.html  1.目标 >> 基于CentOS-6.10-x86_64-minimal ...

  9. 安卓开发时访问google方法

    启动浏览器后15秒左右,浏览器的右上角就会出现图标 启用防火墙功能(右上角墙形图标),这时候程序就会去寻找网上代理,从而达到访问GOOGLE的效果,提示如果不访问google网站,可再点击一下关闭防火 ...

  10. 用C语言构建一个可执行程序的流程

    1.流程图 从用C语言写源代码,然后经过编译器.连接器到最终可执行程序的流程图大致如下图所示. 2.编译流程 首先,我们先用C语言把源代码写好,然后交给C语言编译器.C语言编译器内部分为前端和后端. ...