Start with the question:
Rabbit and grass
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 2097 accepted submission (s): 1579
Problem description university time is romantic, girls are romantic, and Christmas is even more romantic, but rabbit and grass are both not romantic at Christmas this year: they don't go to shopping malls, they don't go to movie parks, they don't go on dates with AC male, and two people are playing chess in the movie ......
Playing chess is actually a simple game. The rules of the game are as follows:
1. The checkerboard contains 1 * n squares, numbered 0, 1, 2,… from left to right ,..., 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. Each step can 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 boundaries of the Board;
5. If all the pawns are on the leftmost side (that is, the number is 0), the game ends, and the final 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 figure shows a 1*15 board with six pawns in total. The position 8 contains two pawns.
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.
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), indicating the number of pieces in the test case, the following line contains M integers ki (I = 1... M; 0 <= Ki <= 1000), indicating the initial position of M pieces, and m = 0 indicates the end of the input.
Output if rabbit can win, please output "Rabbit win !", Otherwise, output "grass win !", The output of each instance occupies one row.
Sample input2 3 533 5 60
Sample outputrabbit win! Grass win! The foundation of the game, the entry to the NIM model, each piece is equivalent to a pile of stones, and the distance from the position to 0 is equivalent to the number of stones, therefore, according to the principle of the NIM model, all numbers are different or the result is obtained at one time. Code:
1 #include <iostream> 2 #include <cstring> 3 #define MAX 1002 4 using namespace std; 5 6 int main() 7 { 8 int n,ans,x; 9 ios::sync_with_stdio(false);10 while(cin>>n,n){11 ans=0;12 for(int i=0;i<n;i++){13 cin>>x;14 ans^=x;15 }16 if(ans) cout<<"Rabbit Win!"<<endl;17 else cout<<"Grass Win!"<<endl;18 }19 return 0;20 }
/X 1849 */