题意

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. R语言-attach、detach、with

    在R语言中,对于串列,数据框中的数据的进行操作时,为了避免重复地键入对象名称,可使用attach或with. 1.attach() 假设data.frame包含列name,age attach(one ...

  2. spring boot: thymeleaf模板引擎使用

    spring boot: thymeleaf模板引擎使用 在pom.xml加入thymeleaf模板依赖 <!-- 添加thymeleaf的依赖 --> <dependency> ...

  3. JDBC 与 Bean Shell的使用(一)获取值,并且传递

    1.在使用Jmeter进行接口测试的时候,会使用到JDBC,连接数据库,操作数据库其得到的数据后续操作需要使用,这里我们使用了BeanShell的概念来获取JDBC的返回值 如下说明了联合使用的2种方 ...

  4. 读写生信流程必备的 Perl 语法

    最早就是写Perl的,后来来到公司转Python,现在又要负责流程了,开始重拾Perl,当然是借鉴别人现有的语法,我再重新组合. 基本语法就不介绍了,参照我之前文章 Perl   模块 use str ...

  5. LeetCode--112--路径总和

    问题描述: 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和. 说明: 叶子节点是指没有子节点的节点. 示例:  给定如下二叉树,以及目标和 s ...

  6. Prime Gift CodeForces - 912E (中途相遇)

    链接 大意:求素因子只含给定素数的第k大数 先二分答案转为判定x是第几大, 然后分两块合并即可, 按奇偶分块可以优化一下常数 #include <iostream> #include &l ...

  7. WaitForMultipleObjects用法详解

    本文转载于:http://blog.csdn.net/sac761/article/details/52456385 WaitForMultipleObjects是Windows中的一个功能非常强大的 ...

  8. CF-499div2-E-裴蜀定理

    E. Border time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  9. UVA-12569 Planning mobile robot on Tree (EASY Version) (BFS+状态压缩)

    题目大意:一张无向连通图,有一个机器人,若干个石头,每次移动只能移向相连的节点,并且一个节点上只能有一样且一个东西(机器人或石头),找出一种使机器人从指定位置到另一个指定位置的最小步数方案,输出移动步 ...

  10. Leetcode 96

    class Solution { public: int numTrees(int n) { ]; dp[] = ; dp[] = ; dp[] = ; ;i <= n;i++){ ; ;j & ...