求助dfsWA#4,悬关
  • 板块CF128A Statues
  • 楼主qwertim
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/6/12 14:20
  • 上次更新2023/10/23 13:18:03
查看原帖
求助dfsWA#4,悬关
780539
qwertim楼主2023/6/12 14:20
#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.......

有没有大佬能解答一下这个测试点是怎么赢的啊,还是我题意理解错了?

2023/6/12 14:20
加载中...