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 & ...
随机推荐
- LOJ 2339 「WC2018」通道——边分治+虚树
题目:https://loj.ac/problem/2339 两棵树的话,可以用 CTSC2018 暴力写挂的方法,边分治+虚树.O(nlogn). 考虑怎么在这个方法上再加一棵树.发现很难弄. 看了 ...
- 在Ubuntu上使用noip动态域名的方法(ddns)
首先,注册一个noip.com的帐号. 注册的步骤见这篇教程:http://www.cnblogs.com/infopi/p/3991407.html 建立目录 第1行进入当前用户的home目录 第2 ...
- Linux patch命令详解
Linux patch命令 Linux patch命令用于修补文件. patch指令让用户利用设置修补文件的方式,修改,更新原始文件.倘若一次仅修改一个文件,可直接在指令列中下达指令依序执行.如果配合 ...
- mybatis 使用oracle merge into 语句踩坑实录
由于需求涉及oracle的clob类型字段,在mybatis的mapper xml文件中编写merge into语句时总是失败. 附上错误代码 <insert id="mergeInt ...
- 4G模块luci的配置及重连脚本
一.4G Luci配置 1. 新建一个wwan接口: 2. 上网方式为dhcp自动获取: 3. 物理设置选择wwan0: 4. 防火墙选择wan 二.重连脚本redial4g LogFile=/roo ...
- web前端性能调优(一)
最近2个月一直在做手机端和电视端开发,开发的过程遇到过各种坑.弄到快元旦了,终于把上线了.2个月干下来满满的的辛苦,没有那么忙了自己准备把前端的性能调优总结以下,以方便以后自己再次使用到的时候得于得心 ...
- git 克隆指定分支
git clone -b v2.8.1 https://git.oschina.net/oschina/android-app.git
- MyBatis中的@Mapper注解及配套注解使用详解(上)
前言: 从mybatis3.4.0开始加入了@Mapper注解,目的就是为了不再写mapper映射文件(那个xml写的是真的蛋疼...).很恶心的一个事实是源码中并没有对于这个注解的详细解释 现在我们 ...
- 快速了解Python的定制类
多重继承 class Student(man,oldman): pass 可以继承多个父类,拥有他们的方法,如果有父类有相同的方法,哪个在前用哪个 定制类 看到类似__slots__这种形如 __xx ...
- git log乱码显示
1.Linux下UTF8编码 [xusi@pre-srv24 crm2]$ localeLANG=en_US.UTF-8 设置如下: git config --global i18n.commiten ...