标签:style http color os io for 问题 ar
题意:给定n堆糖果,每次取一堆任意个数,取到最后一个的输
思路:anti-Nim,推导出来就是如果全为1,判断1的奇偶,如果不为1,就和Nim问题是一样的,判断异或和
代码:
#include <cstdio> #include <cstring> int t, n; bool solve() { scanf("%d", &n); int x, sum = 0, flag = 1; for (int i = 0; i < n; i++) { scanf("%d", &x); if (x > 1) flag = 0; sum ^= x; } if (flag) return n % 2 == 0; else return sum != 0; } int main() { scanf("%d", &t); while (t--) { if (solve()) printf("John\n"); else printf("Brother\n"); } return 0; }
UVA 1566 - John(anti-Nim),布布扣,bubuko.com
标签:style http color os io for 问题 ar
原文地址:http://blog.csdn.net/accelerator_/article/details/38399715