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 }