Problem description A decade ago, China introduced a number of films from abroad every year, including a movie 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, everyone chooses to take the machine test, is a kind of brave (brave) choice; This short semester, we are talking about game (games) topic, so, everyone is playing "brave game", which is why I named this topic.
Of course, in addition to "brave", I also hope to see "good faith", no matter how the test results, want to see is a real result, I also believe that we can certainly do it ~
What is the first game the brave people want to play? Quite simply, it is defined as:
1, the game is a two-person game;
2, there are a lot of stones have n;
3, the two people take turns;
4, each step can take away 1...m of stones;
5, the first to take the light of the side of the stone to win;
If both sides of the game are using the optimal strategy, please output which one will win.
Input data first contains a positive integer c (c<=100), which indicates that there is a C set of test data.
Each set of test data contains a row of two integers n and m (1<=n,m<=1000), and the meanings of N and M are described in the topic.
Output if the first person can win, please export "second", otherwise output "", the output of each instance occupies one row.
Sample Input223 3 Sample Outputfirstsecond Authorlcy sourceacm Short term EXAM_2007/12/13:
Bashbor (Bash game): There are a bunch of n items, two people take turns from the heap to fetch items, take x each time (1≤x≤m). The last person to take the light wins.
If n = m + 1, a maximum of m at a time, so regardless of the first fetch, how many, must also have the remaining X (1≤x≤m). So, after the winner of the win. So we found the secret to winning: if we were to show N as
n = (m + 1) * R + S. (0≤s < M, r≥0). Take the first to take the S, then take away the K (1≤k≤m), then the first take away the M + 1-k. The result is left (M + 1) * (R-1). As long as we always give the opponent a multiple of M + 1, then the first player must win. Now we can know that if s = 0, then the winner wins. Otherwise the first to win the winner.
Code:
1#include <stdio.h>2#include <string.h>3#include <math.h>4#include <algorithm>5#include <iostream>6#include <ctype.h>7#include <iomanip>8#include <queue>9#include <stdlib.h>Ten using namespacestd; One A intMain () - { - intc,n,m,r,s; thescanf"%d",&c); - while(c--){ -scanf"%d%d",&n,&m); -r=n% (m+1); + if(r==0){ -printf"second\n"); + } A Else{ atprintf"first\n"); - } - } -}
Hdu 1846 Brave Game