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

时间:2022-09-02 13:00:20
Cutting Game
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4798   Accepted: 1756

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

2 2
3 2
4 2

Sample Output

LOSE
LOSE
WIN

Source

POJ Monthly,CHEN Shixi(xreborner)
 
 
比较有意思的一道题目,如果你知道什么叫Multi-Nim,那么这道题就比较简单了
最关键的地方就是
一个游戏的SG函数为后继状态异或和的mex
注意边长需要从2枚举,否则2*2这个状态会挂掉
 
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=;
int read()
{
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';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=,M=;
for(int i=;i<=N;i++)
{
for(int j=;j<=N;j++)
{
memset(S,,sizeof(S));
for(int k=;k<=i-;k++) S[ SG[k][j]^SG[i-k][j] ]=;
for(int k=;k<=j-;k++) S[ SG[i][k]^SG[i][j-k] ]=;
for(int k=;;k++) if(!S[k]) {SG[i][j]=k;break;}
}
}
while(scanf("%d%d",&N,&M)!=EOF)
puts(SG[N][M]?"WIN":"LOSE");
return ;
}

POJ 2311 Cutting Game(二维SG+Multi-Nim)的更多相关文章

  1. poj 2155&colon;Matrix(二维线段树,矩阵取反,好题)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17880   Accepted: 6709 Descripti ...

  2. POJ 2155 Matrix (二维线段树)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17226   Accepted: 6461 Descripti ...

  3. poj 1195 Mobile phones&lpar;二维树状数组&rpar;

    树状数组支持两种操作: Add(x, d)操作:   让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...

  4. HDU2873 Bomb Game(二维SG函数)

    Bomb Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. POJ 1661 Help Jimmy&lpar;二维DP&rpar;

    题目链接:http://poj.org/problem?id=1661 题目大意: 如图包括多个长度和高度各不相同的平台.地面是最低的平台,高度为零,长度无限. Jimmy老鼠在时刻0从高于所有平台的 ...

  6. POJ 2155 Matrix【二维树状数组&plus;YY(区间计数)】

    题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  7. POJ 2155 Matrix(二维树状数组&plus;区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

  8. POJ 2155 Matrix (二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17224   Accepted: 6460 Descripti ...

  9. POJ 2019 Cornfields(二维RMQ)

    相比以前的RMQ不同的是,这是一个二维的ST算法 #include<iostream> #include<cstring> #include<cstdio> #in ...

随机推荐

  1. 感恩回馈,新鲜出炉的《ASP&period;NET MVC 5框架揭秘》免费赠送

    上次针对<ASP.NET Web API 2框架揭秘>举办了一次评论赠书活动,很多人问我相同的活动要不要针对<ASP.NET MVC 5框架揭秘>(阅读样章)再来一次,为此我向 ...

  2. MySQL行锁深入研究

    原文:http://blog.csdn.net/minipeach/article/details/5325161/ 做项目时由于业务逻辑的需要,必须对数据表的一行或多行加入行锁,举个最简单的例子,图 ...

  3. 将 project&period;json 项目转换为 Visual Studio 2015 解决方案

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  4. shell处理mysql增、删、改、查

    引言     这几天做一个任务,比对两个数据表中的数据,昨天用PHP写了一个版本,但考虑到有的机器没有php或者php没有编译mysql扩展,就无法使用mysql系列的函数,脚本就无效了,今天写个sh ...

  5. 阿里云数据库RDS环境搭建

    前言 现在云数据库越来越流行,国外的亚马逊AWS微软Azure,国内的BAT和京东都推出了自己的云数据库服务,各自优劣不表,个人推荐国外的用AWS,国内的用阿里云,这是我这几天刚申请的阿里云的过程的一 ...

  6. Eclipse实用快捷键

    经典常用快捷键1. [ALT+/]此快捷键为用户编辑的好帮手,能为用户提供内容的辅助,不要为记不全方法和属性名称犯愁,当记不全类.方法和属性的名字时,多体验一下[ALT+/]快捷键带来的好处吧. 2. ...

  7. cocos2d-x触摸分发器原理

    屏幕捕捉到触摸消息的派发流程: 如果有一个组件如果想要接收触摸事件,会通过继承一个CCTouchDelegate接口注册给CCTouchDispatcher,CCTouchDispatcher 中维护 ...

  8. android做设计的每一个屏幕尺寸和分辨率&lpar;一个&rpar;

    一个.与分辨率无关 1.使用dp(dpi) Android密度不依赖像素(dp)指定屏幕尺寸,它同意不同的屏幕尺寸和像素密度类似设备通过缩放来达到同样的效果. (不解决不同屏幕尺寸的问题?) 2.的资 ...

  9. XML引入以及与html的区别

    1.1 引入 HTML: 负责网页的结构 CSS: 负责网页的样式(美观) Javascript: 负责在浏览器端与用户进行交互. 负责静态的网页制作的语言 HTML语言特点: 1)由标签组成. &l ...

  10. (连通图)Network--POJ--3694

    链接: http://poj.org/problem?id=3694 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82833#probl ...