Cutting Game

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4806   Accepted: 1760

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

分析

dfs求sg值。居然可以这样玩(⊙_⊙)

code

 #include<cstdio>
#include<set>
#include<cstring> using namespace std;
int sg[][]; int get_SG(int w,int h) {
if (sg[w][h] != -) return sg[w][h];
set<int>s;
for (int i=; w-i>=; ++i) //竖直切
s.insert(get_SG(i,h)^get_SG(w-i,h));
for (int i=; h-i>=; ++i) //水平切
s.insert(get_SG(w,i)^get_SG(w,h-i));
for (int j=; ; ++j)
if (!s.count(j)) {sg[w][h] = j;break;}
return sg[w][h]; }
int main () {
memset(sg,-,sizeof(sg));
int w,h;
while (~scanf("%d%d",&w,&h)) {
if (get_SG(w,h)==) puts("LOSE");
else puts("WIN");
}
return ;
}

POJ 2311 Cutting Game(SG函数)的更多相关文章

  1. POJ 2311 Cutting Game(SG函数)

    题目描述 意思就是说两个人轮流剪纸片,直到有一个人剪出1*1的方格就算这个人赢了.然后给出纸片的长和宽,求先手会赢还是会输 (1<=n,m<=200) 题解 看了一眼,这不是裸的SG吗 啪 ...

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

    Cutting Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4798   Accepted: 1756 Desc ...

  3. POJ 2311 Cutting Game (Multi-Nim)

    [题目链接] http://poj.org/problem?id=2311 [题目大意] 给出一张n*m的纸,每次可以在一张纸上面切一刀将其分为两半 谁先切出1*1的小纸片谁就赢了, [题解] 如果切 ...

  4. POJ 2960 S-Nim 博弈论 sg函数

    http://poj.org/problem?id=2960 sg函数几乎是模板题. 调试代码的最大障碍仍然是手残在循环里打错变量名,是时候换个hydra产的机械臂了[超想要.jpg] #includ ...

  5. HDU3544 Alice's Game && POJ 2960 S-Nim(SG函数)

    题意: 有一块xi*Yi的矩形巧克力,Alice只允许垂直分割巧克力,Bob只允许水平分割巧克力.具体来说,对于Alice,一块巧克力X i * Y i,只能分解成a * Y i和b * Y i其中a ...

  6. poj 2311 Cutting Game 博弈论

    思路:求SG函数!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<c ...

  7. poj 2960 S-Nim(SG函数)

    S-Nim Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3694   Accepted: 1936 Description ...

  8. POJ 2311 Cutting Game (博弈)

    题意:给定一个长方形纸张,每次只能水平或者垂直切,如果切到1*1的方格就胜,问先手胜还是负. 析:根据Nim游戏可知,我们可以分别求出每个子游戏的和,就是答案,所以我们就枚举每一种切法,然后求出SG函 ...

  9. poj 2960 S-Nim【SG函数】

    预处理出SG函数,然后像普通nim一样做即可 #include<iostream> #include<cstdio> using namespace std; const in ...

随机推荐

  1. concurrent.futures模块与协程

    concurrent.futures  —Launching parallel tasks    concurrent.futures模块同时提供了进程池和线程池,它是将来的使用趋势,同样我们之前学习 ...

  2. vim常用命令大全

    在命令状态下对当前行用== (连按=两次), 或对多行用n==(n是自然数)表示自动缩进从当前行起的下面n行.你可以试试把代码缩进任意打乱再用n==排版,相当于一般IDE里的code format.使 ...

  3. mui的上拉下载和下拉刷新

    head部分(引入mui) <link href="./resources/css/mui.min.css" rel="stylesheet" /> ...

  4. fish 与oh-my-fish 的安装

    fish 相对于 自带的shell优势很大,最近在研究使用中. 安装教程如下: sudo apt-get install fish oh-my-fish是github上开源项目,使得fish的使用更加 ...

  5. Java中对jsonArray的排序,使用的是Gson

    使用Gson对json解析字符串,转化为json对象. 先上代码: 下面是main方法里面的代码 package testJava; import java.util.ArrayList; impor ...

  6. python3基础08(exec、bytearray使用等)

    #!/usr/bin/env python# -*- coding:utf-8 -*- str="test"print(ascii(str))a=bytearray("a ...

  7. Java栈,PC寄存器,本地方法栈,堆,方法区(静态区)和运行常量池

    详情参考:https://my.oschina.net/wangsifangyuan/blog/711329 前言:当要判断一个变量存在什么空间上哪儿时,先分析它是哪一种(是实例变量还是局部变量),实 ...

  8. pecl install msgpack

    Before the beginning: There are two php version, php5.5, php7.1. we need to install msgpack under ph ...

  9. Object.keys 函数 (JavaScript)

    Object.keys 函数 (JavaScript) 返回对象的可枚举属性和方法的名称. 在实际开发中,我们有时需要知道对象的所有属性,原生js给我们提供了一个很好的方法:Object.keys() ...

  10. 【HDU4507】恨7不成妻(数位DP)

    点此看题面 大致题意: 让你求出一段区间内与\(7\)无关的数的平方和.与\(7\)无关的数指整数中任意一位不为\(7\).整数的每一位加起来的和不是\(7\)的整数倍.这个整数不是\(7\)的倍数. ...