Topic link: http://acm.hdu.edu.cn/showproblem.php?pid=1846
topic:
Problem Description
When I was in college ten years ago, China imported some blockbuster movies from abroad every year. One of them was called "Jumanji" (English name: Zathura). Up to now, I still have some concerns about the computer in the movie. Impressive stunt.
Today, everyone's choice to take the exam on the computer is a brave choice; this short term, we are talking about the topic of game; therefore, everyone is now playing the "Brave's Game", which is also named after me reason for this topic.
Of course, in addition to "brave", I also hope to see "integrity". No matter what the test results are, what I hope to see is a real result. I also believe that everyone can do it~
The first for all brave people to play What is a game? Very simple, it is defined as follows:
1. This game is a two-player game;
2. There are a total of n stones in a pile;
3. Two players take turns;
4. Each step can take 1…m stones;
5. The first player to take all the stones is the winner;
if both sides of the game are using the optimal strategy, please output who can win.
Today, everyone's choice to take the exam on the computer is a brave choice; this short term, we are talking about the topic of game; therefore, everyone is now playing the "Brave's Game", which is also named after me reason for this topic.
Of course, in addition to "brave", I also hope to see "integrity". No matter what the test results are, what I hope to see is a real result. I also believe that everyone can do it~
The first for all brave people to play What is a game? Very simple, it is defined as follows:
1. This game is a two-player game;
2. There are a total of n stones in a pile;
3. Two players take turns;
4. Each step can take 1…m stones;
5. The first player to take all the stones is the winner;
if both sides of the game are using the optimal strategy, please output who can win.
Input
The input data first contains a positive integer C (C<=100), indicating that there are C groups of test data.
Each set of test data occupies one line, including two integers n and m (1<=n, m<=1000). For the meaning of n and m, see the title description.
Each set of test data occupies one line, including two integers n and m (1<=n, m<=1000). For the meaning of n and m, see the title description.
Output
If the first to go wins, output "first", otherwise, output "second", one line per instance.
Sample Input
2 23 2 4 3
Sample Output
first second
Idea: Bash game bare question, as long as n % (m+1) != 0, then the first mover will win, otherwise the first mover will lose.
The code is implemented as follows:
1 #include <cstdio> 2 3 int t, n, m; 4 5 int main() { 6 scanf("%d", &t); 7 while(t--) { 8 scanf("%d%d", &n, &m); 9 if(n % (m + 1) == 0) { 10 printf("second\n"); 11 } else { 12 printf("first\n"); 13 } 14 } 15 return 0; 16 }