Hdu 1849 (Rabbit and Grass) Nim game

Source: Internet
Author: User

Rabbit and Grass

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3864 Accepted Submission (s): 2919


Problem Description University time is romantic, the 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: not to go shopping malls, not to go to the park, not to and AC male dating, Two people even the cat is playing 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 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 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 row containing M integers Ki (i=1...m; 0<=ki<=1000) , which represents the initial position of the m pieces, and m=0 the input at the end.

Output if Rabbit can win, please export "Rabbit win!", otherwise output "Grass win!", the output of each instance takes up one row.

Sample INPUT2 3 533 5 60

Sample Outputrabbit win! Grass win!

Authorlcy

SOURCEACM Short Term EXAM_2007/12/13

Recommendlcy | We have carefully selected several similar problems for you:1848 1404 1729 1730 1524 Simple Nim game
1 //46MS 1580K 303B g++2#include <iostream>3#include <algorithm>4 using namespacestd;5 intMain ()6 {7     intM,a;8      while(Cin>>m &&m)9     {TenCin>>A; Onem--; A         intAns =A; -          while(m--){ -Cin>>A; theAns ^=A; -         } -         if(ans!=0){ -cout<<"Rabbit win!"<<Endl; +}Else{ -cout<<"Grass win!"<<Endl; +         } A     } at     return 0; -}
View Code

Hdu 1849 (Rabbit and Grass) Nim game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.