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. @Async java 异步方法

    在spring 3中,@Async注解能让某个方法快速变为异步执行,马上来先DEMO上手下. 假如在网站的用户注册后,需要发送邮件,然后用户得到邮件确认后才能继续其他工作: 假设发送是一个很耗费时间的 ...

  2. 内核堆分配函数brk()源码分析

    Evernote公开链接:http://www.evernote.com/shard/s133/sh/5b8d3b26-0e53-4c61-aa43-66f6e87bbcb7/a44096dd557f ...

  3. python2 编码问题详解

    实例对比 定义 type str unicode print encode('utf8') decode('utf8') encode('unicode-escape') encode('string ...

  4. Tutorial: Importing and analyzing data from a Web Page using Power BI Desktop

    In this tutorial, you will learn how to import a table of data from a Web page and create a report t ...

  5. (转) ASCII码对应表chr(9)、chr(10)、chr(13)、chr(32)、chr(34)、chr(39)、chr(

    chr(9) tab空格       chr(10) 换行      chr(13) 回车        Chr(13)&chr(10) 回车换行       chr(32) 空格符      ...

  6. UIProgressView swift

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

  7. SQLite函数详解之二

    sqlite3支持的数据类型: NULL.INTEGER.REAL.TEXT.BLOB 但是,sqlite3也支持如下的数据类型 smallint           16位整数 integer    ...

  8. [rsync+inotify]——监控客户端文件变化,rsync同步到服务器

    关于rsync的配置请参考博文:http://www.cnblogs.com/snsdzjlz320/p/5630695.html 实验环境 (1) Rsync服务器:10.0.10.158 (2) ...

  9. 【BZOJ 1997】[Hnoi2010]Planar

    Description Input Output   找到哈密尔顿环之后找到不在哈密尔顿环上的边 这些边如果同时在里面相交那他们同时在外面也相交,所以只能一外一内,这就变成了2-SAT,判一下就好了 ...

  10. shell if判断的种类

    if [ $# != 1 ] ; then echo "USAGE: $0 TABNAME" echo " e.g.: $0 CDR_CALL_20040701" ...