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 & ...
随机推荐
- Spring Cloud Zuul 快速入门
Spring Cloud Zuul 实现了路由规则与实例的维护问题,通过 Spring Cloud Eureka 进行整合,将自身注册为 Eureka 服务治理下的应用,同时从 Eureka 中获取了 ...
- System Generator 参数优化
System Generator 参数优化 通过命令行调试参数 然后编译,查看资源消耗.
- redmine一键安装(项目管理、Bug管理、任务跟踪、代码管理、日报等等)
1,下载一键安装包(64位系统) https://bitnami.com/stack/redmine 2,帮助文档(安装引导) http://www.360doc.com/content/15/033 ...
- Speeding Up The Traveling Salesman Using Dynamic Programming
Copied From:https://medium.com/basecs/speeding-up-the-traveling-salesman-using-dynamic-programming-b ...
- Word中选择中内容后变成C,VMware 虚拟中Ctrl键一直被按住了
Word中选择中内容后变成C: 解决办法:关闭金山词霸的[划词翻译]功能即可. VMware 虚拟中Ctrl键一直被按住了: 解决办法:关闭金山词霸的[取词翻译]功能即可.
- 【idea】之取消@param注释参数错误提示
改为
- JPanel添加键盘监听事件
因为在自己的游戏需求中谢了要用键盘控制飞机的移动,所以用到键盘监听事件,但是使用了JPanel之后添加了键盘监听事件,按相应的方向键飞机并没有反应.但是如果是为JFrame的内容面板加则会有反应. 为 ...
- MongoDB查询结果存放入新的Collection
第一种方法 var lst = db.visits_201501.find({ "url":/http:\/\/m.baidu.com\/application/ }); whil ...
- appium 点击物理按键
有时候我们遇到一些需要点击手机物理返回按键,或者home键等操作,总结如下: adb shell input keyevent 点击home键: adb shell input keyevent 3 ...
- mikrotik ros CVE-2019–3924 DUDE AGENT VULNERABILITY
原文: https://blog.mikrotik.com/security/cve-20193924-dude-agent-vulnerability.html The issue is fixed ...