题目

参考了博客:http://blog.csdn.net/akof1314/article/details/4447709

//0 1 -2
//1 1 -1
//0 2 -1
//1 2 -1
//2 2 -2
//0 3 -1
//1 3 -1
//2 3 -1
//3 3 -2
//0 4 -1
//1 4 -1
//2 4 -1
//3 4 -1
//4 4 -2
//0 5 -1
//1 5 -1
//2 5 -1
//3 5 -1 /*
尼姆博弈。对于N堆的糖,一种情况下是每堆都是1,那么谁输谁赢看堆数就知道;对于不都是1的话,若这些堆是奇异局势,或说他们是非奇异局势,但非奇异局势皆可以转换到奇异局势(具体转变看上一篇介绍)。
经典的尼姆问题是谁哪拿到最后一个则谁赢,本题是拿最后一个的输。下面分析第二种情况:
1.初始给的是奇异局势的话,则先取者为输。
2.初始给的是非奇异局势的话,则先取者为赢。辗转转换非奇异、奇异的次数是相对的。
*/
#include<stdio.h>
#include<string.h> int main(){
int t;
scanf("%d",&t);
while(t--) {
int n;
int a[];
scanf("%d",&n);
int sum=,k=;
for(int i=;i<n;i++) {
scanf("%d",&a[i]);
sum^=a[i];//这样子判断奇异局势吗?用 ^ ?
if(a[i]!=)k=;
}
if(k==) {
if(n%)printf("Brother\n");
else printf("John\n");
}
else {
if(sum==)printf("Brother\n");////这样子判断奇异局势,为0奇异
else printf("John\n");//否则非奇异
}
}
return ;
}

HDU 1907 John(博弈)的更多相关文章

  1. HDU 1907 Nim博弈变形

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

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

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

  3. hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)

    Problem Description Little John is playing very funny game with his younger brother. There is one bi ...

  4. HDU - 1907 John 反Nimm博弈

    思路: 注意与Nimm博弈的区别,谁拿完谁输! 先手必胜的条件: 1.  每一个小游戏都只剩一个石子了,且SG = 0. 2. 至少有一堆石子数大于1,且SG不等于0 证明:1. 你和对手都只有一种选 ...

  5. HDU 1907 John nim博弈变形

    John Problem Description   Little John is playing very funny game with his younger brother. There is ...

  6. HDU 1907 John(取火柴博弈2)

    传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int ...

  7. HDU 1907 John (Nim博弈)

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

  8. hdu 1907 John (尼姆博弈)

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

  9. hdu 1907 John (anti—Nim)

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

随机推荐

  1. 将一个对象相同的属性(不区分大小写)赋值给一个新对象 DataTable的一个简单的扩展

    将一个对象相同的属性(不区分大小写)赋值给一个新对象   1 public static T Mapper<S, T>(S source) 2 { 3 T t = Activator.Cr ...

  2. LeetCode 680. Valid Palindrome II (验证回文字符串 Ⅱ)

    Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...

  3. HDOJ 4705 Y 树形DP

    DP:求出3点构成链的方案数 .然后总方案数减去它 Y Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K ...

  4. centos命令行安装mysql随机密码查看方法(遇到问题及其解决办法)

    mysql初次命令行安装登录时报错: 未输入密码:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwo ...

  5. ArcGIS Runtime SDK for iOS中获取ImageServiceLayer的栅格值

    本文原创,转载请注明原创地址 http://blog.csdn.net/dongyu1009/article/details/37697389 用AGSImageServiceIdentifyTask ...

  6. Cocos2d-x可以实现的效果总结

    Cocos2d-x可以实现的效果总结  动作(Actions) move移动:moveto/moveby 从一个位置移动到另外一个位置 从一个位置移动多少数量级 rotate旋转:rotateto/r ...

  7. 对RDD分区的理解

    举个例子: val logFile = "file:///home/soyo/桌面/6.txt" val conf = new SparkConf().setAppName(&qu ...

  8. CSS小代码汇总整理

    /**实现斑马线的表格*/table.flexme tbody tr:nth-child(2n){background-color:#D6E7FC;} /*返回偶数序的子元素*/table.flexm ...

  9. 适用于zTree 、EasyUI tree、EasyUI treegrid

    #region          System.Text.StringBuilder b_appline = new System.Text.StringBuilder();        Syste ...

  10. $P3931 SAC E一道难题 Tree$

    problem #include <bits/stdc++.h> #define rep(i,j,n) for(register int i=j;i<=n;i++) #define ...