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 }
  • 相关阅读:
    nodejs使用nodemailer发送邮件
    nodemaierl以hotmail(微软邮箱)作为发件人时报错554 5.2.0 STOREDRV.Submission.Exception: OutboundSpamException;
    react 项目部署nginx 配置问题(部署在子目录下)
    nodejs之glob与globby
    package-lock.json的作用
    webpack搭建项目流程(纯干货)
    JS-数组遍历中删除元素的方法优化
    递归tree结构的数据(修改antd tree结构的数据)
    【原创】如何优雅的转换Bean对象
    【解决方案】mysql大数据删除
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/9526574.html
Copyright © 2011-2022 走看看