Solution: Take pebble game (Game)

Title Description
one day Xiao Ming and red stones in play to take the game, the rules of the game is this:

(1) This game is a game for two;

(2) a pile of stones, there are n;

(3) take turns;

(4) can be removed at every step A stone 1 ~ m;

(5) one of the first light-trapping stones, wins.

If the game is using both optimal policy, the output of which people win.
The first input line is a positive integer C (C <= 100), expressed in group C of test data.

Each input two integers n and m (1 <= n, m <= 1000), the meaning of n and m found in the subject description.
Output For each input, if people go first win, please output "first", otherwise output "second".
Sample input
2
23 is 2
. 4. 3
Sample Output
First
SECOND
upper hand win:
When the last becomes n = m + 1, b regardless of how many away, a certain win
so long as the start n = k * (m + 1 ) c + (0 <= c <m +. 1)
A first number c is removed
next time to take the number of b k, a and then take as long as m + 1-k, can be maintained n = k * (m + 1 ) the situation
on the contrary, b wins

#include<iostream>
using namespace std;
int main()
{
 int c,n,m;
 cin>>c;
    while(c--)
 {
  cin>>n>>m;
  if(n%(m+1))
   cout<<"first"<<endl;
  else
   cout<<"second"<<endl;
 }
   return 0;
}

Guess you like

Origin blog.csdn.net/weixin_43540515/article/details/91040360