求助dfsWA#4,悬关*2
  • 板块CF128A Statues
  • 楼主qwertim
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/6/27 21:05
  • 上次更新2023/11/3 12:17:28
查看原帖
求助dfsWA#4,悬关*2
780539
qwertim楼主2023/6/27 21:05
#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
int dx[9]={1,1,1,0,-1,-1,-1,0,0};
int dy[9]={1,0,-1,-1,-1,0,1,1,0};
int M1,M2,p1=11,p2=18;
char c[30][10];
bool ch(){
	fo(i,p1,p2)
		fo(j,1,8)
			if(c[i][j]=='S')return 0;
	return 1;
}
bool check(int x,int y){
	return p1<=x&&x<=p1&&y&&y<9&&c[x][y]!='S';
}
bool dfs(int x,int y){
	if(ch())return 1;
	fo(i,0,8){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(check(nx,ny)&&check(nx-1,ny)){
			p1--,p2--;
			if(dfs(nx-1,ny))return 1;
			p1++,p2++;
		}
	}
	return 0;
}
int main(){
	memset(c,'.',sizeof(c)); 
	fo(i,11,18){
		fo(j,1,8){
			c[i][j]=getchar();
			if(c[i][j]=='M')M1=i,M2=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/27 21:05
加载中...