[POJ2311]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 WH 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.
给出一个N
M的纸片,每次可以把一部分剪成两部分。
谁剪出1*1就胜出了.
本题有多组数据,请做到文件底结束

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


用SG函数最本质的求法,也就是暴力使用mex;n,m不是特别大,所以不会T

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
	int x=0,f=1;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')    f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<1)+(x<<3)+ch-'0';
	return x*f;
}
inline void print(int x){
	if (x>=10)     print(x/10);
	putchar(x%10+'0');
}
const int N=2e2;
int sg[N+10][N+10];
bool vis[N+10];
int n,m;
void prepare(){
	for (int i=2;i<=N;++i)
		for (int j=2;j<=N;++j){
			memset(vis,0,sizeof(vis));
			for (int k=2;k<i-1;++k)	vis[sg[k][j]^sg[i-k][j]]=1;
			for (int k=2;k<j-1;++k)	vis[sg[i][k]^sg[i][j-k]]=1;
			for (int k=0;;k++)	if (!vis[k]){sg[i][j]=k;break;}
		}
}
int main(){
	prepare();
	while (~scanf("%d%d",&n,&m))	printf(sg[n][m]?"WIN\n":"LOSE\n");
	return 0;
}
posted @ 2018-02-08 23:06  Wolfycz  阅读(244)  评论(0编辑  收藏  举报