Hdu1846brave Game (game Theory of Bash Game template title) __ACM

Source: Internet
Author: User
Brave Game Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 11821 accepted Submission (s): 7962


Problem Description Ten years ago, when he was in college, China introduced some films from abroad every year, one of which was 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, we choose to test on the machine, is a kind of courageous (brave) choice; This short term, we are talking about the game (game) topic, so we are playing "the game of the Brave", which is why I named the subject.
Of course, in addition to "brave", I also hope to see "good faith", no matter how the test results, I hope to see is a real result, I also believe that we can certainly do it ~

What is the first game that you brave people want to play? Very simply, it is defined in this way:
1, this game is a two-person game;
2, there are a lot of stones have n;
3, two people in turn;
4, each step can take a 1...m stone;
5. The first one to take light stones wins;

If both sides of the game are using the optimal strategy, please output which person can win.

Input input data first contains a positive integer c (c<=100), which indicates that there is a group C test data.
Each set of test data occupies one row, containing two integers n and m (1<=n,m<=1000), and the meanings of N and M are described in the topic.

Output if the person who goes first can win, please export "second", or the output of each instance takes one row.
Sample Input
2 23 2 4 3
Sample Output
The second
Author LCY
Source ACM Short Term EXAM_2007/12/13
Recommend LCY

Ideas for solving problems: This is a game theory, mainly to investigate the bash game, the main problem is that the title is to consider the relationship between N and m+1 if n% (m+1) ==0 means that this person no matter how to get, his can take light all the stones, based on this idea, Two of the best strategy is to let the other party into the first of the situation, but have congenital advantage, so, just to judge in the absence of stone, whether it is a failure of the situation, if not, in any case, will not win in any case, if it will not win anyway

Deformation problem: The one who takes the last stone fails when (n-1)% (m+1) ==0 is defeated

#include <iostream>    
#include <cstdio>  
#include <stdio.h>  
#include <cstring>    
#include <cstdio>    
#include <climits>    
#include <cmath>   
#include <vector>  
#include <bitset>  
#include <algorithm>    
#include <queue>  
#include <map> 
#define INF 9999999; 
using namespace std;


int n,m,t;
int main ()
{
	cin>>t;
	while (t--)
	{
		cin>>n>>m;
		if (n% (m+1) ==0)
		{
			cout<< "second" <<endl;
		}
		else
		{
			cout<< ' i ' <<endl;
		}
	}
}


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.