POJ2311 Cutting Game 博弈 SG函数
Cutting Game
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 Sample Output LOSE Source POJ Monthly,CHEN Shixi(xreborner)
|
题意:给定w,h ,每次切w×h的方块,先得到1×1方块的人获胜,问先手获胜还是后手获胜 多组数据 (2 ≤ w, h ≤ 200)
题目链接:http://poj.org/problem?id=2311
对于2 * 2, 3 * 3, 2 * 3,先手必输
对于1 * x (x ≥1) 先手必胜
所以每次切的时候都尽量不得到1 * x形式的格子
然后直接套上去就OK了
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector> using namespace std; const int MAXN = ;
int n, m;
int sg[MAXN][MAXN];
bool tf[MAXN * ]; void get_sg() {
for (int i = ; i < MAXN; ++i) sg[][i] = , sg[i][] = ;
for (int i = ; i < MAXN; ++i) {
for (int j = i; j < MAXN; ++j) {
for (int k = ; k < ; ++k) tf[k] = ;
for (int k = ; k <= i - k; ++k) tf[sg[k][j] ^ sg[i - k][j]] = ;
for (int k = ; k <= j - k; ++k) tf[sg[i][k] ^ sg[i][j - k]] = ;
int k = ;
while (!tf[k]) ++k;
sg[j][i] = sg[i][j] = k;
}
}
} int main() {
get_sg();
while (scanf("%d %d", &n, &m) != EOF) {
if (sg[n][m]) printf("WIN\n"); else printf("LOSE\n");
}
return ;
}
POJ2311 Cutting Game 博弈 SG函数的更多相关文章
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
- hdu 3032(博弈sg函数)
题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...
- HDU-4678 Mine 博弈SG函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678 题意就不说了,太长了... 这个应该算简单博弈吧.先求联通分量,把空白区域边上的数字个数全部求出 ...
- (转)博弈 SG函数
此文为以下博客做的摘要: https://blog.csdn.net/strangedbly/article/details/51137432 ---------------------------- ...
- 尼姆博弈+SG函数
博弈这个东西真的很费脑诶.. 尼姆博奕(Nim Game):游戏者轮流从一堆棋子(或者任何道具)中取走一个或者多个,最后不能再取的就是输家.当指定相应数量时,一堆这样的棋子称作一个尼姆堆 当n堆棋子的 ...
- 【转】博弈—SG函数
转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...
- HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)
Fibonacci again and again Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & ...
- Light OJ 1199 - Partitioning Game (博弈sg函数)
D - Partitioning Game Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- LightOJ 1315 - Game of Hyper Knights(博弈sg函数)
G - Game of Hyper Knights Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & ...
随机推荐
- linux curl 命令的使用
有时候需要内网访问接口地址,使用curl命令,带上-v参数 -v 参数可以显示一次 http 通信的整个过程,包括端口连接和 http request 头信息 curl -v http://172.9 ...
- java jvm设置http代理参数
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=1080
- ecstore-自定义app里增加对应的wap的模板
注意第二个参数空第三个参数是自定义app名称$this->page('wap/member/recmembers.html','','ecstoreapprcomp2p');
- matchmove流程中修改Maya相机数据的脚本
matchmove组的流程涉及到syntheyes与maya,nuke交接的问题.syntheyes会生成包含去畸变节点的nuke工程 和带跟踪信息的maya工程.在nuke工程上渲染得到去畸变的序列 ...
- 开始使用Chronograf(官方说明)
地址:https://docs.influxdata.com/chronograf/v1.6/introduction/getting-started/ 开始使用Chronograf 在本页面 入门概 ...
- Azure PowerShell (13) 批量设置Azure ARM Network Security Group (NSG)
<Windows Azure Platform 系列文章目录> 刚刚在帮助一个合作伙伴研究需求,他们的虚拟机全面的网络安全组(Network Security Group, NSG)会经常 ...
- 【java】之java代码的执行机制
要在JVM中执行java代码必须要编译为class文件,JDK是如何将Java代码编译为class文件,这种机制通常被称为Java源码编译机制. 1.JVM定义了class文件的格式,但是并没有定义如 ...
- solrCloud 4.9 分布式集群部署及注意事项
环境搭建 一.zookeeper 参考:http://blog.chinaunix.net/uid-25135004-id-4214399.html 现有4台机器 10.14.2.201 10.14. ...
- PAT 乙级 1083 是否存在相等的差(20 分)
1083 是否存在相等的差(20 分) 给定 N 张卡片,正面分别写上 1.2.…….N,然后全部翻面,洗牌,在背面分别写上 1.2.…….N.将每张牌的正反两面数字相减(大减小),得到 N 个非负差 ...
- 廖雪峰Java2面向对象编程-6Java核心类-2StringBuilder
字符串操作过程中,每次用 + 拼接字符串,有以下问题: 每次循环都会创建新的对象 绝大部分都是临时对象.浪费内存 影响GC效率 String s = ""; for(int i=0 ...