zoukankan      html  css  js  c++  java
  • Cutting Game

    Cutting Game
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions:5544   Accepted: 2022

    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
    

     切卡片,给出一个N*M的纸片,每一次可以把一部分剪成两部分,谁剪出1*1的就赢了.

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

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

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

     1 #include <iostream>
     2 #include <cstring>
     3 #define N 201
     4 using namespace std;
     5 int n,m;
     6 int mex[N][N];
     7 int sg(int x,int y){
     8     if(mex[x][y]!=-1)
     9         return mex[x][y];
    10     int vis[N];
    11     memset(vis,0,sizeof(vis));
    12     for(int i=2;i<=x-i;i++)
    13         vis[sg(i,y)^sg(x-i,y)] = 1;
    14     for(int i=2;i<=y-i;i++)
    15         vis[sg(x,i)^sg(x,y-i)] = 1;
    16     for(int i=0;;i++)
    17         if(vis[i]==0){
    18             return mex[x][y]=i;
    19         }
    20 }
    21 
    22 int main(){
    23     memset(mex,-1,sizeof(mex));
    24     while(~scanf("%d%d",&n,&m)){
    25         if(sg(n,m)==0){
    26             puts("LOSE");
    27         }else{
    28             puts("WIN");
    29         }
    30     }
    31     return 0;
    32 }
  • 相关阅读:
    关于多重条件的搜索查询(sql server+c#)
    sqlserver2005安装错误:性能监视器计数器要求:SQL Server 2005 中为安装程序增加计数器注册表项值....
    javascript动态网页编程实例手册--学习笔记
    asp与asp.net共用session
    如何备份和还原虚拟主机上的数据库到本地
    sql server cannot delete last ''...
    SQL Server 2000的企业管理器无法打开
    asp.net2.0(c#)关于画图的一个例子;
    JBOSS SOA Platform
    C#编译开关
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/9526574.html
Copyright © 2011-2022 走看看