规则类似与NIM博弈,但是取到最后一颗石子的人输
必败态有两种
异或和不为0且(石子数多余1的堆)数目为0
异或和为0且(石子数多余1的堆)数目大于1
1 #include <queue> 2 #include <vector> 3 #include <cstdio> 4 #include <cstring> 5 #include <iostream> 6 #include <algorithm> 7 #define INF 0x3f3f3f3f 8 #define MOD 1000000007 9 using namespace std; 10 typedef long long LL; 11 12 13 14 int main(int argc, const char * argv[]) { 15 int T; 16 scanf("%d", &T); 17 while (T--) { 18 int val; 19 int n;scanf("%d", &n); 20 int tmp = 0, flag = 0; 21 for (int i = 1; i <= n; i++) { 22 scanf("%d", &val); 23 tmp ^= val; 24 if (val > 1) flag ++; 25 } 26 if ((tmp != 0 && flag == 0) || (tmp == 0 && flag > 1)) { 27 puts("Brother"); 28 } else { 29 puts("John"); 30 } 31 } 32 return 0; 33 }