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. SQL语句基础之 管理数据库,表 和 数据

    MySQL中的基本sql语句 MySQL中主要有三个大的对象,第一个是数据库,有了数据库后,我们才能在数据库里面建表,因为Mysql是关系数据库,它的数据都会以记录的形式存到表里,所以第二个是表,然后 ...

  2. Outlook打不开? 进程一大堆!

    问题描述: ====== 关闭Outlook应用程序后,Outlook.exe进程仍在任务管理器里继续运行,不能关闭. 原因: ====== Outlook的插件或者扩展程序阻止Outlook关闭 解 ...

  3. ping通IP,telnet 3306不通

    一个同事装的MySQL数据库,无法连接.​​1.查看权限​​2.查看防火墙​​检查用户权限,防火墙都没问题,就是无法连接,能ping通,但是telnet 3306 端口无法成功.​​检查了下数据库配置 ...

  4. ubuntu常见错误--Could not get lock /var/lib/dpkg/lock解

        通过终端安装程序sudo apt-get install xxx时出错:   E: Could not get lock /var/lib/dpkg/lock - open (11: Reso ...

  5. 六大Nagios常见问题解决办法

    Nagios常见问题1: It appears as though you do not have permission to view information for any of the host ...

  6. [转]ldconfig几个需要注意的地方

    [转]ldconfig几个需要注意的地方 http://www.cnblogs.com/arci/archive/2011/03/19/1988952.html 1. 往/lib和/usr/lib里面 ...

  7. UISegmentedControl swift

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

  8. 0x0A和0x0D

    这里主要是在windows下面做的小实验,linux没有试 先贴源码 #include <iostream> #include <string> #include <st ...

  9. 20145120 《Java程序设计》第7周学习总结

    20145120 <Java程序设计>第7周学习总结 教材学习内容总结 Lambda表达式 例:Comparator<String> byLength = (name1, na ...

  10. 关于arguments对象以及函数的柯里化;

    1.arguments对象 Arguments是个类似数组但不是数组的对象,说他类似数组是因为其具备数组相同的访问性质及方式,能够由arguments[n]来访问对应的单个参数的值,并拥有数组长度属性 ...