#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define fd(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int M1,M2;
char c[10][10],tmp[10][10];
void init(){
fo(i,1,8)
fo(j,1,8)tmp[i][j]=c[i][j];
}
void down(){
init();
fo(i,1,8)
fo(j,1,8){
if(tmp[i-1][j]=='S')c[i][j]='S';
else c[i][j]='.';
}
}
void up(){
init();
fo(i,1,8)
fo(j,1,8){
if(tmp[i+1][j]=='S')c[i][j]='S';
else c[i][j]='.';
}
}
bool ch(){
fo(i,1,8)
fo(j,1,8)
if(c[i][j]=='S')return 0;
return 1;
}
bool check(int x,int y){
return x&&y&&x<9&&y<9&&c[x][y]=='.';
}
bool dfs(int x,int y){
if(ch())return 1;
fo(i,0,3){
int nx=x+dx[i];
int ny=y+dy[i];
if(check(nx,ny)&&check(nx-1,ny)){
down();
if(dfs(nx,ny))return 1;
up();
}
}
return 0;
}
int main(){
fo(i,1,8){
fo(j,1,8){
c[i][j]=getchar();
if(c[i][j]=='M')M1=i,M2=j;
//if(c[i][j]=='A')A1=i,A2=j;
if(c[i][j]!='S')c[i][j]='.';
}
getchar();
}
if(dfs(M1,M2))cout<<"WIN";
else cout<<"LOSE";
return 0;
}
#4测试点:
.......A
........
........
........
........
.SSSSSSS
S.......
M.......
有没有大佬能解答一下这个测试点是怎么赢的啊,还是我题意理解错了?