题意

Language:Default
Cutting Game
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6007 Accepted: 2190

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)

分析

对于任何一个人,都不会先剪出1*n或者n*1,应该这样就必败了。

那我们考虑一个状态的后继中,最小的边也是2,这样就可以避免之前的问题,也不需要考虑类似ANTI-SG。

一旦出现2*2,2*3,3*2,这些都成了终止状态,不论怎么剪都会出现1*n,或者n*1

mex求出不属于集合的最小整数

纸片的SG值是后者的纸片的SG的异或值。

还是考察SG函数

时间复杂度\(O(n^3)\)

代码

#include<iostream>
#include<cstring>
const int N=206;
int n,m,sg[N][N];
int SG(int x,int y){
bool f[N];
memset(f,0,sizeof f);
if(sg[x][y]!=-1) return sg[x][y];
for(int i=2;i<=x-i;++i) f[SG(i,y)^SG(x-i,y)]=1;
for(int i=2;i<=y-i;++i) f[SG(x,i)^SG(x,y-i)]=1;
int t=0;
while(f[t]) ++t;
return sg[x][y]=t;
}
int main(){
// freopen(".in","r",stdin),freopen(".out","w",stdout);
memset(sg,-1,sizeof sg);
sg[2][2]=sg[2][3]=sg[3][2]=0;
while(~scanf("%d%d",&n,&m)) puts(SG(n,m)?"WIN":"LOSE");
return 0;
}

POJ2311 Cutting Game的更多相关文章

  1. [poj2311]Cutting Game_博弈论

    Cutting Game poj-2311 题目大意:题目链接 注释:略. 想法: 我们发现一次操作就是将这个ICG对应游戏图上的一枚棋子变成两枚. 又因为SG定理的存在,记忆化搜索即可. 最后,附上 ...

  2. POJ2311 Cutting Game 博弈 SG函数

    Cutting Game Description Urej loves to play various types of dull games. He usually asks other peopl ...

  3. POJ2311 Cutting Game(博弈论)

    总时间限制: 1000ms 内存限制: 65536kB 描述 Urej loves to play various types of dull games. He usually asks other ...

  4. 【博弈论】【SG函数】poj2311 Cutting Game

    由于异或运算满足结合律,我们把当前状态的SG函数定义为 它所能切割成的所有纸片对的两两异或和之外的最小非负整数. #include<cstdio> #include<set> ...

  5. $POJ2311\ Cutting\ Game$ 博弈论

    正解:博弈论 解题报告: 传送门! 首先看到说,谁先$balabala$,因为$SG$函数是无法解决这类问题的,于是考虑转化成"不能操作者赢/输"的问题,不难想到先剪出$1\cdo ...

  6. 博弈问题之SG函数博弈小结

    SG函数: 给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移 动者判负.事实上,这个游戏可以认为是所有Impartial Combinatorial Ga ...

  7. 博弈论BOSS

    基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...

  8. 【Mark】博弈类题目小结(HDU,POJ,ZOJ)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...

  9. [ACM_几何] Metal Cutting(POJ1514)半平面割与全排暴力切割方案

    Description In order to build a ship to travel to Eindhoven, The Netherlands, various sheet metal pa ...

随机推荐

  1. php7-soap调用wsdl接口报错:Could not connect to host

    由php5.6升级到php7.1以上版本,在用soap调用wsdl接口是报错:Could not connect to host 后来经过排查是centos服务器上装有2个版本的openssl造成的. ...

  2. LeetCode--202--快乐数

    问题描述: 编写一个算法来判断一个数是不是“快乐数”. 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变 ...

  3. hdu-1849-nim模板

    Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. exec可以用来执行语句的

    set @sql='select * from '+@table print @sql exec(@sql)

  5. SQL Server数据库 优化查询速度

    查询速度慢的原因很多,常见如下几种: 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计算列导致查询不优化. 4.内存不足 ...

  6. oracle进行字符串拆分并组成数组

    CREATE OR REPLACE TYPE CUX_STR_SPLIT_TYPE IS TABLE OF VARCHAR2 (4000); CREATE OR REPLACE PACKAGE cux ...

  7. XML Publisher Using API’s(转)

    原文地址:XML Publisher Using API’s Applications Layer APIsThe applications layer of XML Publisher allows ...

  8. OC NSArray数组排序

    一.一般排序 // 排序 NSArray *arr = @["]; NSArray *newarr = [arr sortedArrayUsingSelector:@selector(com ...

  9. spring的FactoryBean

    (以下内容翻译自spring/docs/3.2.18.RELEASE) 为具有工厂属性的对象实现FactoryBean接口. FactoryBean接口是spring IoC 容器实例化逻辑的一点补充 ...

  10. vue-cli的安装及使用

    一.    node 和npm 1.在安装vue-cli前,要确认自己的电脑是否安装了node和npm 2.查询版本如下(vue脚手架支持node@4.xx以上) node -v    查询node版 ...