hdu1907 John--尼姆博弈
2016-12-22 13:57
316 查看
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907
分析:
参考http://www.cnblogs.com/jiangjun/archive/2012/11/01/2749937.html
注意此题是最后取光的是loser。
现在有两个人分别是:先手–pre和后手–nex;
假设现在有n堆,每堆都有若干元素。
这些堆有的只有1个元素,有的堆的元素大于1个,现在把只有一个元素的堆放在左边,元素个数大于1的堆放在右边。
在两人博弈的时候,元素个数大于1的堆,最终,我说的是最终,无外乎变为0或者1,变为1的就放在左边;变为0的直接消失了,不管它。
那么最后一定会出现这样的局面:左边有m堆,m>=0,每个堆的元素个数都是1;右边只有一个堆,元素个数大于1。
现在一个人来取,那么根据m的奇偶性来决定右边的这个堆的剩余个数是0还是1。
AC代码:
分析:
参考http://www.cnblogs.com/jiangjun/archive/2012/11/01/2749937.html
注意此题是最后取光的是loser。
现在有两个人分别是:先手–pre和后手–nex;
假设现在有n堆,每堆都有若干元素。
这些堆有的只有1个元素,有的堆的元素大于1个,现在把只有一个元素的堆放在左边,元素个数大于1的堆放在右边。
在两人博弈的时候,元素个数大于1的堆,最终,我说的是最终,无外乎变为0或者1,变为1的就放在左边;变为0的直接消失了,不管它。
那么最后一定会出现这样的局面:左边有m堆,m>=0,每个堆的元素个数都是1;右边只有一个堆,元素个数大于1。
现在一个人来取,那么根据m的奇偶性来决定右边的这个堆的剩余个数是0还是1。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<vector> #include<cstring> #include<queue> #include<stack> #include<algorithm> #include<cmath> #include<string> #include<stdio.h> #define INF 1000000000 #define EPS 1e-6 using namespace std; int t; int n; int a[50]; int main() { scanf("%d", &t); while (t--) { bool flag = 0; int ans = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); ans ^= a[i]; if (a[i] != 1) flag = 1; } if (flag) { if (ans == 0) printf("Brother\n"); else printf("John\n"); } else { if (n % 2 == 0) printf("John\n"); else printf("Brother\n"); } } return 0; }
相关文章推荐
- HDU1907 John (尼姆博弈变形)
- ACM-尼姆博弈之John——hdu1907
- 20140715 「博弈 - Nim(尼姆)博弈」 HDOJ 1907 John
- HDU1907 John 【博弈】
- POJ 3480 & HDU 1907 John(尼姆博弈变形)
- HDU - 1907 John (反尼姆博弈)
- HDU 1907 John (尼姆博弈新理解)
- POJ 3480 & HDU 1907 John(尼姆博弈变形)
- HDU1907 John 博弈
- John 尼姆博弈
- HDU 1907 John(尼姆博弈之ANTI-SG游戏)
- hdu1907 尼姆博弈
- hdu1907 John 博弈
- hdu1907 John
- John-博弈hdu
- 20140715 「博弈 - Nim(尼姆)博弈」 HDOJ 2509 Be the Winner
- 尼姆博弈
- 尼姆博弈 Match Games
- 尼姆博弈(n堆)
- 【HDU 5996 dingyeye loves stone】+ 尼姆博弈