POJ2311 Cutting Game(博弈论)

总时间限制: 1000ms 内存限制: 65536kB
描述
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.
输入
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.
输出
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".
样例输入
2 2
3 2
4 2
样例输出
LOSE
LOSE
WIN
来源
POJ Monthly,CHEN Shixi(xreborner)

题解:
用sg函数做,还套了个记忆化
切成两半以后,返回的sg值就是两个数的异或。如果有两个必胜,用掉一个,别人再用一个,你就是两个必败了
注意点:为什么要从2开始枚举?
因为如果是1了,先手必胜(非(1,1),可是我的初始化没有设置这种情况,就会出现-1

#include <bits/stdc++.h>
#define int long long
using namespace std;
int sg[230][230], x, y, tong[1200];
bool vis[230][230];
int find(int x, int y) {
    if(sg[x][y]!=-1) return sg[x][y];
    memset(tong, 0, sizeof tong);
    for (int i = 2; i <= x-i; i++)
        tong[(find(i, y)) ^ (find(x - i, y))]=1;
    for (int i = 2; i <= y-i; i++)
        tong[(find(x, i)) ^ (find(x, y - i))]=1;
    for (int i = 0; i < 1200; i++)
        if (!tong[i]) {
            sg[x][y] = i;
            return i;
        }
}
signed main() {
    memset(sg,-1,sizeof sg);
    sg[2][2] = sg[2][3] = sg[3][2] = 0;
    while (scanf("%lld%lld", &x, &y) != EOF) {
        if (!find(x, y))
            puts("LOSE");
        else
            puts("WIN");
    }
    return 0;
}

转载于:https://www.cnblogs.com/wky32768/p/10783126.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值