This question is a matrix board. Let's open this board and look at the two people playing the game in a single row. According to the SG situation definition, we only need to make all the situations different or get the overall game status we want.
Now let's look at a single line. That is to say, if two people move the pawns, if either party cannot go, it will win! In another way, we can see that the game is defeated, that is, when two pieces are adjacent, the first hand is defeated. In this case, we assume that both of them are keen to win and want to reduce the distance between the two pieces, so we can use the SG function to define it, when the SG function value is displayed, it is found that the SG function value is the absolute value of the distance between two pawns minus 1. in fact, this is understandable, because we can see that when two pieces are adjacent to each other, it is a defeat. Therefore, we obtain the SG function value for each game. Finally, you can view the SG function value or view the result to know the status of the entire game.
For the basic content of the game, please read the paper of Yifei, which is very clear.
The following is a simple code:
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;int abst(int a,int b){ int t=a-b; if(t>0) return t; else return 0-t;}int main(){ int ans; int n,m; int a,b; while(scanf("%d %d",&n,&m)!=EOF) { ans=0; for(int i=0;i<n;i++) { scanf("%d %d",&a,&b); ans^=(abst(a,b)-1); } if(ans==0) { printf("BAD LUCK!\n"); } else printf("I WIN!\n"); } return 0;}