(Hdu step 8.2.1) Brave Game .), Hdu8.2.1
Question:
Brave Game |
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission (s): 64 Accepted Submission (s): 54 |
|
Problem Description when I was a university student ten years ago, China introduced some film blockbusters from abroad every year. One of the movies was called "the player's game" (English name: Zathura ), until now, I have been 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 with n in total; 3. 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. |
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 Input223 24 3 |
Sample Outputfirstsecond |
Authorlcy |
SourceACM Short Term Exam_2007/12/13 |
Recommendlcy
|
Question Analysis:
If n % (m + 1) = 0. Why is it a late winner? However, you only need to set the number of stones in the front hand (m + 1-the number of stones in the front hand. In other cases, assume n = (m + 1) * r + s (where r can be 0 ). At this time, as long as the first time the forehand took s, each time the number of stones and the total number of hind hands = m + 1. In summary, when n % (m + 1 )! If the value is 0, the front hand wins. Otherwise, the latter wins.
The Code is as follows:
/**. Cpp ** Created on: March 25, 2015 * Author: Administrator */# include <iostream> # include <cstdio> using namespace std; int main () {int t; scanf ("% d", & t); while (t --) {int n, m; scanf ("% d", & n, & m ); if (n % (m + 1) = 0) {// printf ("second \ n") WHEN n % (m + 1) = 0 "); // It is the winner} else {// otherwise printf ("first \ n"); // It is the winner} return 0 ;}