Cutting Game
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions:5544 |
|
Accepted: 2022 |
Descriptionios
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.
Inputui
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.
Outputspa
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 Inputrest
2 2
3 2
4 2
Sample Outputcode
LOSE
LOSE
WIN
切卡片,给出一个N*M的纸片,每一次能够把一部分剪成两部分,谁剪出1*1的就赢了.blog
对于任何一我的,都不会先剪出1*n或者n*1,应该这样就必败了。ip
那咱们考虑一个状态的后继中,最小的边也是2,这样就能够避免以前的问题,也不须要考虑相似ANTI-SG。get
一旦出现2*2,2*3,3*2,这些都成了终止状态,不论怎么剪都会出现1*n,或者n*1.input
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 }