HDU 2147 kiki's game (game + NP state diagram + law)

Question portal The
meaning of the question: two people play chess, both are extremely smart (anyway, the players are extremely smart). The size of the chessboard is n*m (n rows and m columns). The initial chess piece is located at the upper right corner, which is at coordinates (1, m). The rule of the game is to move this chess piece, and you can only move it to the left, down, or There are three ways to move in the bottom left, and the person who can't move the piece first loses. Now the first player is Pharaoh, and ask whether Pharaoh will win? If the output victory Wonderful !, Otherwise output A pity the What! .
Idea: Obvious game problem, but it is a bit different from the Bash game. We have no choice but to draw the NP state diagram. Remember the following definition of the NP state? The
ending position is always P.
N: The person in this turn must win the game, and there must be a losing situation in the subsequent state. P
P: The person in this turn must lose the game, and all subsequent states are in a winning situation. N

For example, n = 5 m = 3, the
Insert picture description here
starting point for NP drawing is P, the first move must be defeated, so the old king will lose in this round,
but I feel that after drawing the picture, I still don’t know the law of this topic. Draw several different situations and constrain different numbers of n and m. , After some twists and turns, finally came to the following conclusion

  • If both n and m are odd numbers, the first mover must lose, that is, the old king must lose
  • Anyway, the first mover must win, that is, the old king must win

The code is as follows c++

#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string.h>
using namespace std;
const int N = 2e3+10;
const double PI = acos(-1.0);

signed main(void)
{
    
    
    int n,p,q,m;
    while(cin>>n>>m&&!cin.eof()){
    
    
        if(n==0&&m==0) break;
        if((n&1)&&(m&1)) cout<<"What a pity!"<<endl;
        else cout<<"Wonderful!"<<endl;
    }
}

Game is really a metaphysics

Guess you like

Origin blog.csdn.net/YSJ367635984/article/details/113763920