POJ 2311 Cutting Game(二维SG+Multi-Nim)
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
3 2
4 2
Sample Output
LOSE
LOSE
WIN
Source
POJ Monthly,CHEN Shixi(xreborner)
比较有意思的一道题目,如果你知道什么叫Multi-Nim,那么这道题就比较简单了
最关键的地方就是
一个游戏的SG函数为后继状态异或和的mex
注意边长需要从2枚举,否则2*2这个状态会挂掉
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=233;
int read()
{
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int SG[MAXN][MAXN];//当前剩余i行 j列的SG函数
int S[MAXN];
int main()
{
#ifdef WIN32
freopen("a.in","r",stdin);
#else
#endif
int N=201,M=201;
for(int i=2;i<=N;i++)
{
for(int j=2;j<=N;j++)
{
memset(S,0,sizeof(S));
for(int k=2;k<=i-2;k++) S[ SG[k][j]^SG[i-k][j] ]=1;
for(int k=2;k<=j-2;k++) S[ SG[i][k]^SG[i][j-k] ]=1;
for(int k=0;;k++) if(!S[k]) {SG[i][j]=k;break;}
}
}
while(scanf("%d%d",&N,&M)!=EOF)
puts(SG[N][M]?"WIN":"LOSE");
return 0;
}
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 利用PHP如何统计Nginx日志的User Agent数据
- PHP树形结构tree类用法示例
- PHP PDOStatement::errorCode讲解
- Laravel框架搜索分页功能示例
- 解决Keras TensorFlow 混编中 trainable=False设置无效问题
- 浅谈keras中的后端backend及其相关函数(K.prod,K.cast)
- 使用 prometheus python 库编写自定义指标的方法(完整代码)
- PHP PDOStatement::fetchColumn讲解
- PHP PDOStatement::bindValue讲解
- PDO::lastInsertId讲解
- thinkPHP框架RBAC实现原理分析
- PHP PDOStatement::debugDumpParams讲解
- PDO::prepare讲解
- sklearn的predict_proba使用说明
- 如何使用python记录室友的抖音在线时间