Brave Game
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 10947 Accepted Submission (s): 7362
Problem description A decade ago, China introduced a number of films from abroad every year, including a movie called "The Game of the Brave" (English Name: Zathura), and until now I was still impressed by some of the computer stunts in the movie.
Today, everyone chooses to take the machine test, is a kind of brave (brave) choice; This short semester, we are talking about game (games) topic, so, everyone is playing "brave game", which is why I named this topic.
Of course, in addition to "brave", I also hope to see "good faith", no matter how the test results, want to see is a real result, I also believe that we can certainly do it ~
What is the first game the brave people want to play? Quite simply, it is defined as:
1, the game is a two-person game;
2, there are a lot of stones have n;
3, the two people take turns;
4, each step can take away 1...m of stones;
5, the first to take the light of the side of the stone to win;
If both sides of the game are using the optimal strategy, please output which one will win.
Input data first contains a positive integer c (c<=100), which indicates that there is a C set of test data.
Each set of test data contains a row of two integers n and m (1<=n,m<=1000), and the meanings of N and M are described in the topic.
Output if the first person can win, please export "second", otherwise output "", the output of each instance occupies one row.
Sample Input223 24 3
Sample Outputfirstsecond
Authorlcy
Source
ACM Short Term EXAM_2007/12/13
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): 8892 Accepted Submission (s): 5638
Problem description for Sichuan compatriots suffering from the disaster, the people 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 data first contains a positive integer c, which represents the C set of test cases, followed by the C row of data, each row contains 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, export the string "Grass", if Xu can be selected, output the string "Rabbit", the output of each instance is one row.
Sample INPUT28 1011 10
Sample Outputgrassrabbit
Authorlcy
Source
2008-06-18 "ACM Program Design" Final Exam--Sichuan refueling! China Refueling!
Ba Shi Game (theorem presented):
Only a bunch of n items, two people take turns from this pile of goods, the provision of at least one at a time, the maximum number of M. The last person to take the light wins the victory.
n = (m+1) R+s, (R is any natural number, s≤m), that is, n% (m+1)! = 0, the first-pick winner.
Ba Shi game is still a good understanding of the drip, you are the initiator of the point of view. You want to break up your opponent, then every inning, you have to build a situation, the situation is that each time left to the opponent M+1 several times items (why left to m+1 times will be able to win, you have a little brain to come out). So not only to take the game can use the Ba Shi theorem, but also can be counted off and so on, to see who first report 100. And the number of each report must be 1~10 (including 1 and 10), then you should always leave the opponent the remaining number of the number of 11 multiples.
--------------------------------------------------------------
A. Ba Shi game, a person to take 1~m, that who face m+1 situation of the time will be defeated, it is clear that the first to take is to create this situation, if n is (m+1) *r+s (k for any, s<m+1), then it is clear that the first take off S, Then no matter how much you can make sure that you take the m+1 after the end, so you will have to face the inevitable situation, such as 232,23= (3x7) +2; that's the first time I took 2, and then no matter how many times the second I can make this round a total of 3, and then he must face 3 this situation, Then I will win, then when will be defeated, it is obvious if I face is (m+1) multiples of the situation will be defeated.
Code:
1#include <iostream>2 using namespacestd;3 intMain ()4 {5 intn,m,t;6Cin>>T;7 while(t--)8 {9Cin>>n>>m;Ten if(n% (m+1)==0) cout<<"Rabbit"<<Endl; One Elsecout<<"Grass"<<Endl; A } - return 0; -}
*hdu1846hdu2188 Bashbor Game