zoukankan      html  css  js  c++  java
  • POJ2311 Cutting Game

    题意

    Language:
    Cutting Game
    Time Limit: 1000MSMemory Limit: 65536K
    Total Submissions: 6007Accepted: 2190

    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
    

    Source

    POJ Monthly,CHEN Shixi(xreborner)

    分析

    对于任何一个人,都不会先剪出1*n或者n*1,应该这样就必败了。

    那我们考虑一个状态的后继中,最小的边也是2,这样就可以避免之前的问题,也不需要考虑类似ANTI-SG。

    一旦出现2*2,2*3,3*2,这些都成了终止状态,不论怎么剪都会出现1*n,或者n*1

    mex求出不属于集合的最小整数

    纸片的SG值是后者的纸片的SG的异或值。

    还是考察SG函数

    时间复杂度(O(n^3))

    代码

    #include<iostream>
    #include<cstring>
    const int N=206;
    int n,m,sg[N][N];
    int SG(int x,int y){
    	bool f[N];
    	memset(f,0,sizeof f);
    	if(sg[x][y]!=-1) return sg[x][y];
    	for(int i=2;i<=x-i;++i) f[SG(i,y)^SG(x-i,y)]=1;
    	for(int i=2;i<=y-i;++i) f[SG(x,i)^SG(x,y-i)]=1;
    	int t=0;
    	while(f[t]) ++t;
    	return sg[x][y]=t;
    }
    int main(){
    //	freopen(".in","r",stdin),freopen(".out","w",stdout);
    	memset(sg,-1,sizeof sg);
    	sg[2][2]=sg[2][3]=sg[3][2]=0;
    	while(~scanf("%d%d",&n,&m)) puts(SG(n,m)?"WIN":"LOSE");
    	return 0;
    }
    
  • 相关阅读:
    ExtJs 第二章,Ext.form.Basic表单操作
    linux centos 下php的mcrypt扩展
    curl_errno错误码说明
    centos 安装composer
    虚拟机centOs Linux与Windows之间的文件传输
    CentOS 6.4 linux下编译安装 LNMP环境
    CentOS 6.4 php-fpm 添加service 添加平滑启动/重启
    CentOS 6.4 linux下编译安装MySQL5.6.14
    centOS linux 下PHP编译安装详解
    centOS linux 下nginx编译安装详解
  • 原文地址:https://www.cnblogs.com/autoint/p/10574616.html
Copyright © 2011-2022 走看看