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. android打开文件、保存对话框、创建新文件夹对话框(转载)

    转载地址:点击打开 这是一个简单的只有3个按钮的程序,3个按钮分别对应三种工作的模式(保存.打开和文件夹选择).封装的SimpleFileDialog.java的内容如下: package com.e ...

  2. 斐波那契数列【java实现】

    java 实现斐波那契数列 以下是Java代码实现(递归与递推两种方式): import java.util.Scanner; /** * Fibonacci * * @author tongqian ...

  3. 移植MAVLINK到STM32详细教程之三

    在前面教程的基础上继续移植优化,之前的没有加缓冲区,没有接收函数功能,这里进行统一的讲解                            作者:恒久力行  qq:624668529 缓冲区对于接 ...

  4. 学习笔记:MDN的JavaScript

    JavaScript 第一步 什么是JavaScript? 每次当你浏览网页时不只是显示静态信息—— 显示即时更新的内容, 或者交互式的地图,或 2D/3D 图形动画,又或者自动播放视频等,你可以确信 ...

  5. The sventh day

    call it a day 是个相当古老的习惯用语,沿用至今已经有一百五十多年了,但是人民仍然常常用到她. call it a day 可不是“叫一天”的意思哦, 这里是收工的,下班的意思 I thi ...

  6. WIN10+Ubuntu14.04 双系统 ubuntu无法有线上网的问题

    注:在WIN10 的引导下安装了双系统,ubuntu有线无法上网,无线却可以. 上网一查,发现之前许多安装双系统的人都存在以上的问题. 常见的解决方法是: 在WINDOWS下关闭网络唤醒,还有一些检查 ...

  7. pat甲级1016

    1016 Phone Bills (25)(25 分) A long-distance telephone company charges its customers by the following ...

  8. POI 怎么设置Excel整列的CellStyle啊

    POI 怎么设置Excel整列的CellStyle啊,而不是循环每个Cell.因为现在是生成Excel模板,不知道客户会输入多少行. 问题补充: 指尖言 写道 好像没有这个方法,CellStyle是C ...

  9. hdu-1874 畅通工程续---模板题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1874 题目大意: 求起点到终点的最短距离 解题思路: 注意重边,其他的就是模板 #include&l ...

  10. Android(java)学习笔记81:在TextView组件中利用Html插入文字或图片

    1. TextView中利用Html插入文字或者图片: 首先我们看看代码: (1)activity_main.xml: <LinearLayout xmlns:android="htt ...