1363幻想迷宫
  • 板块学术版
  • 楼主pizzazz
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/7/15 20:03
  • 上次更新2023/11/3 09:39:12
查看原帖
1363幻想迷宫
944415
pizzazz楼主2023/7/15 20:03
/*

5 4
##.#
##S#
#..#
#.##
#..#
5 4
##.#
##S#
#..#
..#.
#.##

*/

#include<bits/stdc++.h>
using namespace std;

int fx[5]={0,0,1,0,-1};
int fy[5]={0,1,0,-1,0};
bool bj1=false;
int n,m,x,y;
char a[1510][1512];
bool bj[1510][1510];
void dfs(int x,int y){
	bj[x][y]=false;
	for(int i=1;i<=4;i++){
		int tx=fx[i]+x;
		int ty=fy[i]+y;
		if(tx>0&&ty>0&&tx<=n&&ty<=m&&a[tx][ty]!='#'&&bj[tx][ty]==true){
	    	if(bj[1][ty]==false&&tx==n) 
	    		bj1=true;
			else if(bj[tx][1]==false&&ty==m)
				bj1=true;
			else if(bj[n][ty]==false&&tx==1)
				bj1=true;
			else if(a[tx][m]==false&&ty==1)
				bj1=true;
	    	dfs(tx,ty);
		}
	}
}
int main(){
	int o=0;
	while(true){
		memset(bj,true,sizeof(bj));
		memset(a,0,sizeof(a));
		cin>>n>>m;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cin>>a[i][j];
				if(a[i][j]=='S'){
					x=i;
					y=j;
				}
			}
		}
		dfs(x,y);
		if(bj1==true){
			o++;
			bj1=false;
		}
		else if(bj1==false){
			for(int i=1;i<=o;i++){
				cout<<"Yes"<<endl;
			}
			cout<<"No";
			return 0;
		}
	}
	return 0;
}

2023/7/15 20:03
加载中...