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 split命令详解
Linux split命令 Linux split命令用于将一个文件分割成数个.该指令将大文件分割成较小的文件,在默认情况下将按照每1000行切割成一个小文件. 将输入内容拆分为固定大小的分片并输出到 ...
- asp.net:如何实现负载均衡方案讨论 (nginx+iis实现负载均衡)
5台阿里云服务器,ip地址分别为 ip地址 名字简称 操作系统 iis服务器 cpu 内存DDR3 机械硬盘 11 ...
- RHEL 6.5系统安装配置图解教程(rhel-server-6.5)
转自:http://www.jb51.NET/os/128752.html 说明: 截止目前RHEL 6.x最新版本为RHEL 6.5,下面介绍RHEL 6.5的具体安装配置过程 服务器相关设置如下: ...
- Ubuntu 安装以及web服务器配置
1.安装实在没必要说,连系统都装不了,干脆下岗算了 2.Apache2 安装 //安装 sudo apt-get install apache2 Apache安装完成后,默认的网站根目录是" ...
- 荣耀9少 gms core服务
1.首先安装gms core即本软件gms安装器,安装时候会重启一次. gms core apk下载地址:http://www.paopaoche.net/android/307559.html 注意 ...
- gulp学习总结
一.gulp使用-博客推荐: http://www.sheyilin.com/2016/02/gulp_introduce/ 二.gulp的作用 gulp是一个前端构建工具,它是一个工具框架,可以通过 ...
- PAT 乙级 1076 Wifi密码 (15)
下面是微博上流传的一张照片:“各位亲爱的同学们,鉴于大家有时需要使用wifi,又怕耽误亲们的学习,现将wifi密码设置为下列数学题答案:A-1:B-2:C-3:D-4:请同学们自己作答,每两日一换.谢 ...
- mina2的processor
processor顾名思义,就是进行IO处理,处理当前session的数据读写,并进行业务处理. 在mina server初始化的时候,会初始化一个processor池,通过NioSocketAcce ...
- python programming作业5
# -*- coding: utf-8 -*- class ageError(Exception): pass class salaryError(Exception): pass class s ...
- 学习笔记之Introduction to Data Visualization with Python | DataCamp
Introduction to Data Visualization with Python | DataCamp https://www.datacamp.com/courses/introduct ...