poj 2311 cutting game
来源:互联网 发布:照片眨眼张嘴软件 编辑:程序博客网 时间:2024/05/29 15:40
Cutting Game
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 3553 Accepted: 1323
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 23 24 2
Sample Output
LOSELOSEWIN
Source
POJ Monthly,CHEN Shixi(xreborner)
题解:sg函数的博弈问题。刚开始看这道题的时候,有些无从下手。后经过小动物(orz zyx神犇)的指点,才明白如何建立SG函数。
这道题就是一个N*M的方格,两个人轮流去切,可以横着切,也可以竖着切,第一个切出一个方格的人胜利,问先手是否有必胜策略。首先很容易想到的就是如果只有一行或只有一列那么先手只需要切下一个方格就必胜了。那么我们可以这么想每次都是一刀把方格切成两部分,那么两个部分共同影响当前的状态,也就是当前状态等于两个部分异或的答案,因为只有当两部分都是必胜的才能保证当前必胜,所以可以通过不断细分去求解。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n,m,sg[210][210];void get_sg(){ bool hash[50003]; for (int i=2;i<=200;i++) for (int j=2;j<=200;j++) { memset(hash,0,sizeof(hash)); for (int k=2;k+k<=i;k++) hash[sg[k][j]^sg[i-k][j]]=1; for (int k=2;k+k<=j;k++) hash[sg[i][k]^sg[i][j-k]]=1; for (int k=0;;k++) if (!hash[k]) { sg[i][j]=k; break; } }}int main(){ memset(sg,0,sizeof(sg)); get_sg(); while (scanf("%d%d",&n,&m)==2) { if (!sg[n][m]) printf("LOSE\n"); else printf("WIN\n"); }}
0 0
- POJ 2311 Cutting Game
- POJ-2311-Cutting Game
- POJ 2311 Cutting Game
- POJ - 2311 Cutting Game
- POJ 2311 Cutting Game
- poj 2311 cutting game
- poj 2311 Cutting Game
- POJ 2311 Cutting Game 笔记
- poj 2311 Cutting Game(sg函数)
- POJ 2311 Cutting Game (SG函数)
- poj 2311 Cutting Game (sg函数)
- poj 2311 Cutting Game sg函数
- POJ 2311 Cutting Game (sg函数)
- POJ 2311 Cutting Game SG函数
- poj 2311 Cutting Game SG函数
- POJ 2311 Cutting Game (sg博弈)
- POJ 2311 Cutting Game SG函数
- POJ 2311 Cutting Game 博弈,sg函数
- Java复习(4)-异常处理
- 容器的capacity、max_size以及内存分配
- 3365: [Usaco2004 Feb]Distance Statistics 路程统计 点分治
- 自定义简易相机
- 自定义View实例——下雨天画面(通过布局文件.xml中的自定义属性来设值)
- poj 2311 cutting game
- 线索二叉树及其遍历
- 关于JNI杂记
- discuz登陆相关
- Android中JSON数据的解析
- Unity关于图形学基础-矩阵的行列式(六)
- 读书笔记
- Android的Binder的起源-android学习之旅(100)
- NumPy的教程--数组,基本运算