解题报告 poj 2311 cutting game

                                                                          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 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

(本弱鸡是看了别的题解才get到的,首先这道题的关键是如何建立SG函数,本人还是对博弈理解的不够深刻啊,其次很多时候T是因为多了些不必要的操作,比如多初始化数组,多赋一次值,多一句无用的判断,这些在做其他题目时也要注意,最后,emmm...先这样吧)

题意:多组输入W H,表示宽W高H的网格纸,两人轮流沿着格线切割,谁先切下一个小格子谁就获胜,问先手能否获胜

思路:SG函数打表,切完一刀该被切纸张分为两部分,当两部分都能保证先手胜时先手才能真正获胜,而当前的状态为两部分状态的抑或值,两个for循环(数据量不大)进行打表求出每种情况的SG值。

#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int vis[1005];
int sg[205][205];
int w,h;
int getsg(int w,int h)
{
    if(sg[w][h]!=-1)
        return sg[w][h];
    memset(vis,0,sizeof(vis));//一定不要写在if前边不然会T
    for(int i=2;2*i<=w;i++)//切割时的边最小为2,i<=w-i,因为i>w-i的情况在之前已经判断过,避免重复
        vis[getsg(i,h)^getsg(w-i,h)]=1;
    for(int i=2;2*i<=h;i++)
        vis[getsg(w,i)^getsg(w,h-i)]=1;
    for(int i=0;;i++)
        if(!vis[i])return sg[w][h]=i;
}
int main()
{
    memset(sg,-1,sizeof(sg));
    while(cin>>w>>h)
    {
        if(getsg(w,h))cout<<"WIN"<<endl;
        else cout<<"LOSE"<<endl;
    }
     return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值