bzoj1022: [SHOI2008]小约翰的游戏John

http://blog.csdn.net/cjk_cjk/article/details/43380249

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<algorithm>
 5 #include<iostream>
 6 
 7 using namespace std;
 8 
 9 void setIO(const string& s) {
10     freopen((s + ".in").c_str(), "r", stdin);
11     freopen((s + ".out").c_str(), "w", stdout);
12 }
13 template<typename Q> Q read(Q& x) {
14     static char c, f;
15     for(f = 0; c = getchar(), !isdigit(c); ) if(c == '-') f = 1;
16     for(x = 0; isdigit(c); c = getchar()) x = x * 10 + c - '0';
17     if(f) x = -x;
18     return x;
19 }
20 template<typename Q> Q read() {
21     static Q x; read(x); return x;
22 }
23 
24 int main() {
25 #ifdef DEBUG
26     freopen("in.txt", "r", stdin);
27     freopen("out.txt", "w", stdout);
28 #endif
29     
30     int T = read<int>(), x, n, xor_sum, flag;
31     while(T--) {
32         read(n);
33         xor_sum = 0; flag = 1;
34         while(n--) {
35             read(x);
36             if(x ^ 1) flag = 0;
37             xor_sum ^= x;
38         }
39         
40         puts((flag ^ (bool)xor_sum) ? "John" : "Brother");
41     }
42     
43     return 0;
44 }
View Code

 

posted @ 2016-01-06 21:41  Showson  阅读(190)  评论(0编辑  收藏  举报