Day11 - J - Brave Game HDU - 1846

Ten years ago was a college student, China should introduce some movies from abroad each year, including a movie called "Jumanji" (English name: Zathura), until now, I am still part of the movie for computers stunt impressive.
Today, we choose the machine exam, it is a brave (brave) choice; the short term, we are talking about is the game (game) theme; therefore, we are now playing is "Jumanji," This is my name the reason this topic.
Of course, in addition to "brave", I also want to see "good faith", regardless of test scores, would like to see is a real result, I believe we will be able to do it -

you want to play first brave What game is it? Very simple, it is defined as:
1, this game is a game for two;
2, there is a pile of stones, a total of n;
3, the two take turns;
4, every step can be removed 1 ... m one stone;
5, one of the first to take the light stone of the winner;

if both games are using the optimal strategy, please output which people win.

Input data is first input comprising a positive integer C (C <= 100), expressed in group C of test data.
Each test per line, comprising two integers n and m (1 <= n, m <= 1000), n and m have the meaning described in the subject.
Output If people go first win, please output "first", otherwise output "second", the output of each instance per line. Sample Input

2
23 2
4 3

Sample Output

First 
SECOND 

classic Bash game problem, 0 is a P-state, 1 ~ m a N state, the m + 1 is the P state, m + 2 ~ 2m + 1 is N state, 2 (m + 1) is P state such push, when the (m + 1) | n, when is the P state, the upper hand will be lost, in other words, when the (m + 1) | n, the upper hand can select only 1 ~ m, will be able to take FLAC m + 1 of the left one, FLAC must win, otherwise, the upper hand will take n% (m + 1), corresponding to flip into the state sente
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;


void run_case() {
    int n, m; 
    cin >> n >> m;
    if(n%(m+1)==0) cout << "second\n";
    else cout << "first\n";
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int t; cin >> t;
    while(t--)
    run_case();
    cout.flush();
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/GRedComeT/p/12312562.html