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;
    }
    
  • 相关阅读:
    dubbo开发中使用到的一些服务配置方式
    jedis连接池详解(Redis)
    《Java线程池》:任务拒绝策略
    BlockingQueue(阻塞队列)详解
    洛谷 P3275 BZOJ 2330 [SCOI2011]糖果
    LaTeX的简单使用方法
    洛谷 P1131 BZOJ 1060 [ZJOI2007]时态同步
    洛谷 P2587 BZOJ 1034 [ZJOI2008]泡泡堂
    苦酒入喉心作痛,红酒入鹅鹅想哭——震惊!勒索病毒想哭靠wine感染了Ubuntu16.04
    洛谷 P2144 BZOJ 1003 [FJOI2007]轮状病毒
  • 原文地址:https://www.cnblogs.com/autoint/p/10574616.html
Copyright © 2011-2022 走看看