POJ 2311. Cutting Game

Link
meaning of problems:
given a \ (N * M (2 \ le n, m \ le 200) \) of the rectangular grid paper, two players take turns.
In each operation, the sheet can be optionally a rectangular grid, the grid line along a row or a column, to cut it into two parts.
First cut \ (1 * 1 \) players lined paper wins.
Two players are the best strategy to take action, whether seeking the upper hand to win.
Idea:
get \ (1 * 1 \) , in addition to go through \ (1 * n \) and \ (n * 1 \) to these two win situation, we will go through \ (2 * 2 \) , \ ( 2 * 3 \) , \ (3 * 2 \) of these three situations, but these three will get the situation back to win the first two situations, so these three losing situation for the situation
we have to win for three The final situation for recursive
\ (sg [i, j] = mex ((sg [x, j] \ bigoplus s [ix, j]) (2 <= x <= i / 2) \ cup sg [i, x ] \ bigoplus s [i, jx ]) (2 <= x <= j / 2)) \)
Code:

#include<iostream>
#include<cstring>

using namespace std;


const int N=210;

int sg[N][N];
bool vis[N];

int main() {
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(sg,-1,sizeof sg);
    for(int i=2;i<=N;i++)
        for(int j=2;j<=N;j++) {
            if(sg[i][j]<0) {
                memset(vis,false,sizeof vis);
                for(int k=2;k<=i/2;k++) {
                    vis[sg[k][j]^sg[i-k][j]]=true;
                }
                for(int k=2;k<=j/2;k++) {
                    vis[sg[i][k]^sg[i][j-k]]=true;
                }
                for(int k=0;;k++) if(!vis[k]) {sg[i][j]=sg[j][i]=k;break;}
            }
        }
    int n,m;
    while(cin>>n>>m) {
        if(sg[n][m]) cout<<"WIN"<<endl;
        else cout<<"LOSE"<<endl;
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/c4Lnn/p/12536241.html