HDU 1846 brave game (Bashi game)
Description
When I went to college ten years ago, China introduced some film blockbusters from abroad every year. One of them was called "the player's game" (Name: zathura). Until now, I am still impressed by some of the Computer stunts in the movie. Today, we chose the computer test as a brave choice. In this short term, we are talking about the game topic. Therefore, now everyone is playing the "multiplayer game", which is why I name this question. Of course, in addition to being brave, I also hope to see "integrity". No matter what the test scores are, what I want to see is a real result. I believe everyone can do it ~
What is the first game to be played by beginners? It is very simple. It is defined as follows: 1. This game is a two-person game; 2. There are a pile of stones and a total of N; 3. The two take turns; 4. Each step can take 1... M stones; 5. the first party to win the light stones;
If both sides of the game are using the best strategy, please output which one can win.
Input
The input data first contains a positive integer c (C <= 100), indicating that there are group C test data. Each group of test data occupies one row and contains two integers n and M (1 <= n, m <= 1000). For the meanings of N and M, see the topic description.
Output
If a leader can win, output "first"; otherwise, output "second". The output of each instance occupies one row.
Sample Input
223 24 3
Sample output
First
Second
(1) bash game: there are only a bunch of N items, two people take things in turn from the pile of items, each time at least one, a maximum of M. The final winner wins. Obviously, if n = m + 1, a maximum of m items can be taken at a time. Therefore, no matter how many items are taken by the first accessor, the latter can take the remaining items at a time, the latter wins. Therefore, we discovered the rule of How to Win: If n = (m + 1) R + S, (R is an arbitrary natural number, S ≤ m ), the first accessors must take s items. If the second accessors take K (≤ m) items, the first accessors take m + 1-K items, and the result is (m + 1) (r-1), and later to maintain such a method, then the first accessors certainly win. In short, we need to leave a multiple (m + 1) to the opponent to win. This game can also have a disguised gameplay: two people report at least one message each time, and a maximum of ten messages each time. Who can report to the 100 winner.
The Pn diagram is also very easy to draw. I understand that N is the winner of the latter, and P is the winner of the latter.
1 #include <iostream> 2 3 using namespace std; 4 5 int main() 6 { 7 int i,n,m; 8 cin>>i; 9 while(i--)10 {11 cin>>n>>m;12 if(n%(m+1)!=0)13 {14 cout<<"first will win!"<<endl;15 }16 else17 {18 cout<<"second will win!"<<endl;19 }20 }21 return 0;22 }
Game Theory 2