博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2311 Cutting Game(二维SG+Multi-Nim)
阅读量:4507 次
发布时间:2019-06-08

本文共 2341 字,大约阅读时间需要 7 分钟。

Cutting Game
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4798   Accepted: 1756

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 23 24 2

Sample Output

LOSELOSEWIN

Source

,CHEN Shixi(xreborner)
 
 
比较有意思的一道题目,如果你知道什么叫Multi-Nim,那么这道题就比较简单了
最关键的地方就是
一个游戏的SG函数为后继状态异或和的mex
注意边长需要从2枚举,否则2*2这个状态会挂掉
 
#include
#include
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;}

 

转载于:https://www.cnblogs.com/zwfymqz/p/8465524.html

你可能感兴趣的文章
基础知识回顾——上下文管理器
查看>>
ARM(RISC)和x86(CISC)的技术差异
查看>>
第3章 对象基础
查看>>
文件压缩与解压缩
查看>>
android 搜索自动匹配关键字并且标红
查看>>
Android ViewPager使用详解
查看>>
python爬虫之scrapy的pipeline的使用
查看>>
mysql 1366错误
查看>>
mfc 导出数据保存成excel和txt格式
查看>>
让Android中的webview支持页面中的文件上传
查看>>
UML基础
查看>>
Oracle 从Dump 文件里提取 DDL 语句 方法说明
查看>>
实现winfrom进度条及进度信息提示
查看>>
关于Spring.Net的singleton和singlecall的讨论
查看>>
vue项目目录结构
查看>>
程序员自学路上的一些感悟
查看>>
使用x64dbg分析微信聊天函数并实现发信息
查看>>
robotframework-selenium2library各个版本
查看>>
插入排序
查看>>
LeetCode全文解锁 √
查看>>