Miyu original, post Please note: Reprinted from
__________ White House
Question address:
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1849
Description: Problem description
University time is romantic, girls are romantic, and Christmas is even more romantic, but the two college girls rabbit and grass are not romantic at all this year's Christmas: do not go to the mall, don't go to the park, don't go on a date with AC male, two people are playing chess in the park ......
Playing chess is actually a simple game. The rules of the game are as follows:
1 , The Board contains 1 * N squares, numbered from left to right as 0, 1 , 2 ,..., N - 1 ;
2 Place M pieces on the checker Square. The square can be empty or more than one piece;
3 The two sides take turns playing chess;
4 In each step, you can choose to move any piece to any position on the left (multiple pieces can be placed in the same square). Of course, any piece cannot go beyond the boundary of the Board;
5 If all the pawns are on the leftmost side (that is, the number is 0), the game ends and the last player is the winner.
For this question, you do not need to consider the size of N (we can assume that in the initial state, the pawn is always in the proper position of the Board ). The following is a 1*There are a total of six chess pieces on the 15th board, of which there are two chess pieces at the position of 8.
As you know, although occasionally not romantic, rabbit and grass are both ice and snow smart girls. If every time Rabbit goes first, please output the final result.
input
the input data contains multiple groups of test cases. Each test case occupies two rows. The first row contains an integer m ( 0 <= m <= 1000 ) indicates the number of pawns in this test case, the following line contains M integers ki (I = 1 ... M; 0 <= Ki <= 1000 ), represents the initial position of M pieces, respectively. m = 0 ends the input.
Output
If rabbit can win, output "Rabbit win!", Otherwise, output" grass win!", The output of each instance occupies one row.
Sample Input
2
3 5
3
3 5 6
0
Sample output
Rabbit win!
Grass win!
Question Analysis:Miyu original, post Please note: Reprinted from__________ White House
The standard Nim game problem should not be complicated. because it can only move to the left, we can regard the initial position of each piece as a heap. For example, if one piece is in the n-1 lattice, it indicates that the heap has n-1 numbers.
Move the 1 cell left, that is, take away one, so m pieces represent M heaps, all to 0 is finished ............ for more information about the NIM game, click <getting started with games>
CodeAs follows:Miyu original, post Please note: Reprinted from__________ White House
# Include < Iostream >
Int Heap [ 1001 ];
Int Main ()
{
Int T;
While (Scanf ( " % D " , & T), T)
{
Int Res = 0 , Ncount = 0 ;
For ( Int I = 0 ; I ! = T; ++ I)
{
Scanf ( " % D " , Heap + I );
Res ^ = Heap [I];
}
Puts (Res = 0 ? " Grass win! " : " Rabbit win! " );
}
Return 0 ;
}