MLE求助
查看原帖
MLE求助
1073282
jijiladajiji楼主2024/4/13 18:53
#include<bits/stdc++.h>
using namespace std;
int dx[5]={0,1,-1,0,0};
int dy[5]={0,0,0,-1,1};
struct xp{
	int x,y;
};
int n,m;
char a[114][514];
void bfs(){
	queue<xp>q;
	xp sb;
	sb.x=1;
	sb.y=1;
	q.push(sb);
	while(!q.empty()){
		xp now=q.front();
		q.pop();
		for(int i=1;i<=4;i++){
			int xx=now.x+dx[i];
			int yy=now.y+dy[i];
			if(xx>=1&& xx<=n && yy>=1 && yy<=m && a[xx][yy]!='#'){
				if(xx==n && yy ==m){
					cout<<"Yes";
					return;
				}
				xp next;
				next.x=xx;
				next.y=yy;
				q.push(next);	
			}
		}
		
	}
	cout<<"No";
	return;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	bfs();
	

}
2024/4/13 18:53
加载中...