Source: HDU 2188 Tribute to 512 Wenchuan earthquake victims--selection of volunteers
Tribute to the 512 Wenchuan earthquake--selection of volunteers
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 6923 Accepted Submission (s): 4378
Problem Description
For the disaster suffered by the Sichuan compatriots, the people of the country have reached a helping hand, almost every provinces and cities have sent a large number of rescue workers, including emergency relief of the armed police force, treatment and prevention of medical personnel, as well as psychological counseling psychology experts. According to the requirements, our school also has a disaster relief in the area, because the vast number of teachers and students enrolled enthusiastically, the school had to conduct a selection to determine the final candidate. After several rounds of examination, the situation is gradually clear, the final quota will be in the "Lin" and "Xu team" between the production. But coincidentally, 2 people's resume almost identical, this makes the host selection of 8600 is very embarrassed. Helpless, he decided to donate money to decide who can be selected.
The selection rules are as follows:
1, the original donation box is empty;
2. The two persons make a round contribution, each of which must be a positive integer, and each donation is not more than M (1<=m<=10) per person.
3, the first to make total contributions to reach or exceed N yuan (0<n<10000) of the party as the winner, it can be pro-disaster services.
We know that both of us want to be on the volunteer list, and are very smart people, assuming the forest team first donate, please judge who can be selected in the final list?
Input
The input data first contains a positive integer c, which represents the C set of test cases, followed by the C row of data, each line containing two positive integers n,m,n and m meaning see the rules mentioned above.
Output
For each set of test data, if the forest can be selected, output the string "Grass", if Xu can be selected, output string "Rabbit", the output of each instance occupies one row.
Sample Input
2
8 10
11 10
Sample Output
Grass
Rabbit
Main topic:
Two people through donations to select volunteers, the total amount of donations is n, each person to donate the maximum amount of m, each person at least one yuan each time, the first to make a donation to n or more than n Yuan winner, the first donor wins the output ' Grass ', after the donor wins the output ' Rabbit '.
Topic Analysis:
This question should be the basic Bashbor, because it is the first to win the light, so we assume that n= (m+1) *r+k,r for the natural number, k<m+1, the first to take the winner, you need to ensure that after the pick is the m+1 of a multiple, that is, first take k, and then whichever is taken to take the number of G bar, the first to take Ensure that the remainder is a multiple of m+1, so that the final first pick will win.
AC Code:
#include <stdio.h>int main () {int t,n,m;scanf ("%d", &t), while (t--) {scanf ("%d%d", &n,&m); if (n% (m+1) )//To determine whether K is 0, if 0, then the first person to lose printf ("grass\n"); elseprintf ("rabbit\n");} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 2188 Tribute to 512 Wenchuan earthquake victims--selection of volunteers (Bashbor)