1022: [SHOI2008] Little John's game John time limit: 1 Sec Memory Limit: 162 MB
Submit: 1375 Solved: 865
[Submit] [Status] Description
Little John often plays a very interesting game with his elder brother: there are n heaps of stones on the table, and Little John and his brother take the stones in turn, and when everyone takes it, they can choose a heap of stones at random, take away any number of stones in this heap of stones, but not a stone nor take it, we stipulate that the person who takes the last Little John is very stubborn, he insists that the first person has a great advantage, so he always take the stone first, and his brother is much smarter, he has never made mistakes in the game. John asked you to be his adviser before he was angry. Naturally, you should first write a program that predicts who will win the game.
Input
The input of the subject consists of multiple sets of data, and the first line consists of an integer t, which indicates that the input has a total of T-group data (t≤500). The first row of each set of data consists of an integer n (n≤50), which represents a total of n heap stones, followed by N of an integer not exceeding 5000, representing the number of stones per heap.
Output
The output of each group of data takes one row, and each line outputs a word. If John can win the game, output "John", otherwise output "Brother", please note the word case.
Sample Input2
3
3 5 1
1
1Sample OutputJohn
BrotherHINT
"Data Size"
For 40% of data, t≤250.
For 100% of data, t≤500.
Source
Seerc2007
Thesis question, Anti-nim game.
In two cases:
1. All of the heaps are 1:
SG value is 0 (even number of heaps), the initiator win
2. There are more than 1, the others are 1 (at this time the SG value is obviously not 0), then the initiator must be able to make the current into an odd number of heaps, each heap is 1;
If there are more than 1, if the SG is not 0, let him become 0 (then after the operation of the SG must not be 0, and eventually become a bunch of more than 1, SG not 0)
Comprehensive:
If each heap is all 1, sg=0 the initiator to win;
If at least a bunch of more than 1, sg!=0 to win.
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm>using namespace Std;int Main () { int t;scanf ("%d", &t), while (t--) {int n;scanf ("%d", &n); int Ans=0,x;bool F=true;while (n--) {scanf ("%d", &x), Ans^=x;if (x!=1) F=false;} if ((F&&!ans) | | | (!f&&ans)) printf ("john\n"); else printf ("brother\n");} return 0;}
"Bzoj 1022" [SHOI2008] Little John's game John