码迷,mamicode.com
首页 > 其他好文 > 详细

POJ - 2311 Cutting Game

时间:2015-08-02 13:44:34      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

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

#include <cstdio>
#include <set>
#include <cstring>
using namespace std;

int g[210][210];

int grundy(int W, int H) {
	if (g[W][H] != -1) return g[W][H];

	set<int> s;
	for (int i = 2; i <= W / 2; i++) s.insert(grundy(i, H) ^ grundy(W - i, H));
	for (int i = 2; i <= H / 2; i++) s.insert(grundy(W, i) ^ grundy(W, H - i));

	int res = 0;
	while (s.count(res)) res++;
	return g[W][H] = res;
}

int main() {
	int W, H;
	memset(g, -1, sizeof(g));
	while (scanf("%d%d", &W, &H) != EOF) {
		if (grundy(W, H)) puts("WIN");
		else puts("LOSE");
	}
	return 0;
}

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ - 2311 Cutting Game

标签:

原文地址:http://blog.csdn.net/kl28978113/article/details/47206333

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!