Cutting Game
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2844   Accepted: 1036

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)
 
sg函数
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set> using namespace std; const int MAX_N = ;
int dp[MAX_N][MAX_N]; int grundy(int w, int h) {
if(dp[w][h] != -) return dp[w][h]; set<int> s;
for(int i = ; w - i >= ; i++) {
s.insert(grundy(i, h) ^ grundy(w - i,h));
}
for(int i = ; h - i >= ; ++i) {
s.insert(grundy(w, i) ^ grundy(w, h - i));
} int res = ;
while(s.count(res)) res++;
return dp[w][h] = res;
} int main()
{
//freopen("sw.in","r",stdin);
int w, h; for(int i = ; i <= ; ++i) {
for(int j = ; j <= ; ++j) dp[i][j] = -;
}
while(~scanf("%d%d",&w,&h)) {
printf("%s\n",grundy(w, h) ? "WIN" : "LOSE");
}
//cout << "Hello world!" << endl;
return ;
}

poj 2311的更多相关文章

  1. POJ 2311 Cutting Game (Multi-Nim)

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

  2. 【POJ 2311】 Cutting Game

    [题目链接] http://poj.org/problem?id=2311 [算法] 博弈论——SG函数 [代码] #include <algorithm> #include <bi ...

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

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

  4. POJ 2311 Cutting Game(Nim博弈-sg函数/记忆化搜索)

    Cutting Game 题意: 有一张被分成 w*h 的格子的长方形纸张,两人轮流沿着格子的边界水平或垂直切割,将纸张分割成两部分.切割了n次之后就得到了n+1张纸,每次都可以选择切得的某一张纸再进 ...

  5. poj 2311 Cutting Game 博弈论

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

  6. POJ 2311 Cutting Game(SG+记忆化)

    题目链接 #include<iostream> #include<cstdio> #include<cstring> using namespace std; ][ ...

  7. POJ 2311 Cutting Game [Multi-SG?]

    传送门 题意:n*m的纸片,一次切成两份,谁先切出1*1谁胜 Multi-SG? 不太一样啊 本题的要求是后继游戏中任意游戏获胜就可以了.... 这时候,如果游戏者发现某一单一游戏他必败他就不会再玩了 ...

  8. 4.1.7 Cutting Game(POJ 2311)

    Problem description: 两个人在玩如下游戏. 准备一张分成 w*h 的格子的长方形纸张,两人轮流切割纸张.要沿着格子的边界切割,水平或者垂直地将纸张切成两部分.切割了n次之后就得到了 ...

  9. POJ 2311 Cutting Game(SG函数)

    Cutting Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4806   Accepted: 1760 Desc ...

随机推荐

  1. rspec的一些常见用法

    这里讲了如何安装rspec,安装使用rspec. 下面介绍一下rspec中常见的使用方法. 下面是一个最简单的测试用例,判断true是不是等于true,should_be是旧的用法,新用法推荐使用ex ...

  2. hihoCoder-1000-A+B

    题目描述:传统的A+B题 使用语言:C 代码: #include <stdio.h> int main(void){ int a,b; while((scanf("%d %d&q ...

  3. SQL 跟踪方法相关介绍

    oracle sql跟踪方法:1.sql_trace打开跟踪:alter session set sql_trace=true;为跟踪文件做标记:alter session set tracefile ...

  4. Effiective C++ (一)

    最近在看Effective  C++ ,同时将总结一下里边的重要知识点: ##########################    module  1    #################### ...

  5. C语言中断言ASSERT

    我一直以为assert仅仅是个报错函数,事实上,它居然是个宏,并且作用并非"报错". 在经过对其进行一定了解之后,对其作用及用法有了一定的了解,assert()的用法像是一种&qu ...

  6. bootsrap check 获取选中

    代码如下: <label> <input type="checkbox" name="PartEdge2" value="false ...

  7. button swift

    // // ViewController.swift // UILabelTest // // Created by mac on 15/6/23. // Copyright (c) 2015年 fa ...

  8. .gitignore无效,不能过滤某些文件

    利用.gitignore过滤文件,如编译过程中的中间文件,等等,这些文件不需要被追踪管理. 现象: 在.gitignore添加file1文件,以过滤该文件,但是通过git status查看仍显示fil ...

  9. 在本地环境用虚拟机win2008 sever搭建VS2013 + SVN 代码版本控制环境

    此文仅仅是自己笔记做个备忘.因为自己开发一些中小型的软件经常需要修修改改,特别是winform界面的大改动.经常需要对版本进行管理.而租用分布式服务器和远程服务器都不是自己想要的.本文结合虚拟机 + ...

  10. Valuable site on github

    https://thegrid.io/?utm_source=adwords&utm_medium=cpc&utm_campaign=thegrid-display-english&a ...