HDU 1846 brave game]

Source: Internet
Author: User
Link: http://acm.hdu.edu.cn/showproblem.php? PID = 1846 http://acm.hust.edu.cn/vjudge/contest/view.action? Cid = 29256 # Problem/bbrave game

Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 4744 accepted submission (s): 3126


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 the first person wins, output "first"; otherwise, output "second". The output of each instance occupies one row.


Sample Input

223 24 3
 


Sample output

firstsecond
 


Authorlcy


Sourceacm short term exam_2007/12/13


Recommendlcy

Algorithm: Bashi game click to Open Materials

Naked Bashi game:
There are only one pile of N items, and two people take things from the pile of items in turn,
It is required that at least one is required, and a maximum of M is allowed. The final winner wins.

Conclusion:
If n % (m + 1 )! = 0, the first winner wins
Otherwise, the latter wins... PS: It seems that the primary school or kindergarten children are playing this orz... Let's take a look at the code of the quiz exercise where the children are playing:

/*************************************** * ********* Naked Bashi game: there are only one pile of N items, and two people take things from the pile of items in turn, each time at least one, a maximum of M. The final winner wins. Conclusion: If n % (m + 1 )! = 0 then the first winner wins otherwise the latter wins... It seems that elementary school children are playing this orz ****************************** * ********************/# include <stdio. h> int main () {int t; int A, B; scanf ("% d", & T); While (t --) {scanf ("% d", & A, & B); if (a % (B + 1) = 0) printf ("second \ n "); else printf ("first \ n");} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.