前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >POJ 2311 Cutting Game(二维SG+Multi-Nim)

POJ 2311 Cutting Game(二维SG+Multi-Nim)

作者头像
attack
发布2018-04-10 18:26:43
8030
发布2018-04-10 18:26:43
举报

Description

Urej loves to play various types of dull games. He usually asks other people to play with him. He says that playing those games can show his extraordinary wit. Recently Urej takes a great interest in a new game, and Erif Nezorf becomes the victim. To get away from suffering playing such a dull game, Erif Nezorf requests your help. The game uses a rectangular paper that consists of W*H grids. Two players cut the paper into two pieces of rectangular sections in turn. In each turn the player can cut either horizontally or vertically, keeping every grids unbroken. After N turns the paper will be broken into N+1 pieces, and in the later turn the players can choose any piece to cut. If one player cuts out a piece of paper with a single grid, he wins the game. If these two people are both quite clear, you should write a problem to tell whether the one who cut first can win or not.

Input

The input contains multiple test cases. Each test case contains only two integers W and H (2 <= W, H <= 200) in one line, which are the width and height of the original paper.

Output

For each test case, only one line should be printed. If the one who cut first can win the game, print "WIN", otherwise, print "LOSE".

Sample Input

代码语言:javascript
复制
2 2
3 2
4 2

Sample Output

代码语言:javascript
复制
LOSE
LOSE
WIN

Source

POJ Monthly,CHEN Shixi(xreborner)

比较有意思的一道题目,如果你知道什么叫Multi-Nim,那么这道题就比较简单了

最关键的地方就是

一个游戏的SG函数为后继状态异或和的mex

注意边长需要从2枚举,否则2*2这个状态会挂掉

代码语言:javascript
复制
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=233;
int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int SG[MAXN][MAXN];//当前剩余i行 j列的SG函数 
int S[MAXN];
int main()
{
    #ifdef WIN32
    freopen("a.in","r",stdin);
    #else
    #endif
    int N=201,M=201;
    for(int i=2;i<=N;i++)
    {
        for(int j=2;j<=N;j++)
        {
            memset(S,0,sizeof(S));
            for(int k=2;k<=i-2;k++) S[ SG[k][j]^SG[i-k][j] ]=1;    
            for(int k=2;k<=j-2;k++) S[ SG[i][k]^SG[i][j-k] ]=1;
            for(int k=0;;k++) if(!S[k]) {SG[i][j]=k;break;}
        }
    }
    while(scanf("%d%d",&N,&M)!=EOF)
        puts(SG[N][M]?"WIN":"LOSE");
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-02-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档