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. [css filter]filter在界面实现滤镜效果

    最近逛当当,发现当当尾品会的首页推荐最底端的商品链接是灰色的图片,然后鼠标hover之后就会变成正常的彩色 肯定不是通过img来改变的,然后直接看了一下源码,其实是用的filter属性 _(:з」∠) ...

  2. 改用二进制启动Moses translation model提示Can't read ~/working/binarised-model/reordering-table

    解决方案: 换成 /home/用户名/working 貌似就好使了...但是时间还是估计太长,明早挂机一天试试,顺便把manual 的详细部分看了

  3. WPF实现渐变淡入淡出的动画效果

    1.实现原理 1.1 利用UIElement.OpacityMask属性,用于改变对象区域的不透明度的画笔.可以使元素的特定区域透明或部分透明,从而实现比较新颖的效果. 1.2 OpacityMask ...

  4. .NET开源工作流RoadFlow-流程设计-流程步骤设置-按钮设置

    按钮设置是配置当前步骤的处理者可以执行哪些操作,每个按钮都有对应的执行脚本(javascript脚本). 从左边的按钮列表中选择当前步骤需要的按钮. 注意:如果是流程最后一步则要配置完成按钮而不是发送 ...

  5. js实现对身份证校验

    var vcity={ 11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古&quo ...

  6. Excel日期格式提取year

    Excel日期格式提取year =TEXT(YEAR(C2),"0000")

  7. Android HTTP session && cookie

    HTTP协议与状态保持HTTP协议本身是无状态的,这与HTTP协议本来的目的是相符的,客户端只需要简单的向服务器请求下载某些文件,无论是客户端还是服务器都没有必要纪录彼此过去的行为,每一次请求之间都是 ...

  8. oracle12c不能进入到http://localhost:5500/em的解决办法

    Oracle11g企业管理器无法打开——解决https://localhost:1158/em 页面无法打开的问题 常见的问题:https://localhost:1158/em 无法打开 解决办法: ...

  9. django-pagination的使用

    1.安装django-pagination 2.将文件夹pagination复制到项目的根目录下 3.修改settings: 1.将 'pagination.middleware.Pagination ...

  10. 消息点击事件的响应链---hitTest:withEvent:方法

    *当用户点击屏幕时,会产生一个触摸事件,系统会将触摸事件加入到 UIApplication管理事件队里中 *UIApplication 会从事件队列中取出最前面的事件进行分发以便处理,通常,先发送事件 ...