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 & ...
随机推荐
- SpringBoot 项目创建网站
https://start.spring.io/
- MySQL状态变量详解
MySQL状态变量详解 mysql的状态变量(status variables)记录的mysql服务器的运行状态信息.查看语法如下: SHOW [GLOBAL | SESSION] STATUS; S ...
- spring-jar包及架构介绍
查看博客: http://www.cnblogs.com/ywlaker/p/6136625.html
- excel技巧--批量生成工资条
要想生成如上图的工资条,快速的方法如下: 1.在工资表右侧建立一升序数字列,完成后再复制该列,重复粘贴一次在该列底部.2.对该表排序:“开始”-->“排序和筛选”-->自定义排序.在对话框 ...
- Azure PowerShell (13) 批量设置Azure ARM Network Security Group (NSG)
<Windows Azure Platform 系列文章目录> 刚刚在帮助一个合作伙伴研究需求,他们的虚拟机全面的网络安全组(Network Security Group, NSG)会经常 ...
- sp_who, sp_who2和sp_who3
sp_who可以返回如下信息: (可选参数LoginName, 或active代表活动会话数)Spid (系统进程ID)status (进程状态)loginame (用户登 ...
- vi 编辑器基本命令
命令模式(esc) k 上移一行j 下移一行h 左移一行l 右移一行 6j 下移6行 5k 上移5行 0 将游标放在一行的开始$ 将游标放在一行的末尾w 将游标移动到下一个单词b 将游标移动到上一个 ...
- P【1012】拼数
十分蒟蒻...(还是看别人的博才过的...) 题解 #include<cstdio>#include<cstring>#include<algorithm>#inc ...
- [转][MVC]更新 dll 后版本不匹配的问题
<dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken=" ...
- 1118 Birds in Forest (25 分)
1118 Birds in Forest (25 分) Some scientists took pictures of thousands of birds in a forest. Assume ...