1849-rabbit and Grass
problem Description
College time is romantic, girls are romantic, Christmas is more romantic, but rabbit and grass the two college girls in this year's Christmas is not a bit romantic: do not go shopping malls, do not go to the park, and AC male dating, two people unexpectedly cat in the sleep at night chess ...
Said to be chess, in fact, is just a simple little game, the rules of the game is this:
1, the chessboard contains 1*n, squares from left to right respectively numbered as 0,1,2,...,n-1;
2, M pieces on the chessboard on the grid, squares can be empty, can also put more than one piece;
3, the two sides take turns moves;
4, each step can choose any one of the pieces to move to the left to any position (can be multiple pieces in the same square), of course, any pieces can not exceed the board boundaries;
5. If all the pieces are on the leftmost (i.e. numbered 0), the game is over and the final moves is specified as the winner.
For the subject, you do not need to consider the size of N (we can assume that in the initial state, the pawn is always in the appropriate position on the board). The following schematic is a 1*15 board, a total of 6 pieces, of which the number 8 position has two pieces.
You know, although occasionally not romantic, but rabbit and grass are clever girls, if every time is rabbit first moves, please output the final result.
Input
The input data contains multiple sets of test cases, each of which occupies two rows, and the first line contains an integer m (0<=m<=1000), representing the number of pieces of this test case, followed by a line containing M integers Ki (i=1...m; 0<=ki<=1000), The initial position of the m pieces is indicated, and m=0 is the end input.
Output
If Rabbit can win, please output "Rabbit win!", otherwise output "Grass win!", the output of each instance takes up one row.
Sample Input
2
3 5
3
3 5 6
0
Sample Output
Rabbit win!
Grass win!
Title Link: HDU-1849
Topic idea: Actually is also the classic Nim question, transforms, a pawn is equivalent to a pile of stone, the pawn in X's position namely this pile has x stone
Here's the code:
#include <iostream> #include <iomanip> #include <fstream> #include < sstream> #include <cmath> #include <cstdio> #include <cstring> #include <cctype> #include <algorithm> #include <functional> #include <numeric> #include <string> #include <set> # Include <map> #include <stack> #include <vector> #include <queue> #include <deque> #
Include <list> using namespace std;
int main () {int m;
while (Cin >> m && m) {int ans = 0,num;
for (int i = 0; i < m; i++) {cin >> num;
Ans ^= num;
} if (ans) cout << "Rabbit win!\n";
else cout << "Grass win!\n";
} return 0; }