求助
  • 板块学术版
  • 楼主hkl99
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/30 19:44
  • 上次更新2024/7/30 19:51:04
查看原帖
求助
770439
hkl99楼主2024/7/30 19:44

为啥有一个测试点没过

B3625 迷宫寻路

#include<bits/stdc++.h>
using namespace std;
int n,m,fx[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
bool isok=true;
char a[110][110];
struct node{
	int x,y;
};
void bfs(){
	queue <node> q;
	node t;
	t.x=1;
	t.y=1;
	a[1][1]='#';
	q.push(t);
	while(!q.empty()){
		t=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			int nx=t.x+fx[i][1];
			int ny=t.y+fx[i][0];
			if(nx==n&&ny==m){
				isok=false;
				cout<<"Yes";
				return;
			}
			if(nx>0&&nx<=n&&ny>0&&nx<=m&&a[nx][ny]=='.'){
				a[nx][ny]='#';
				node tt;
				tt.x=nx;
				tt.y=ny;
				q.push(tt);
				
			}
		}
	}
	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();
	if(isok){
		cout<<"No";
	}
	return 0;
}

求大老解决

2024/7/30 19:44
加载中...