@[2345A](/user/565070)
```cpp
#include<iostream>
#include<queue>
#include<bits/stdc++.h>
#define N 110
using namespace std;
typedef struct d{
int x,y,z;
}point;
int m,n,x,y,ans=1;
char str[N][N];
int arr[N][N];
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
void bfs(){
int a,b;
queue<point> q;
point t,g;
arr[x][y]=1;
t.x=x,t.y=y,t.z=1;
q.push(t);
while(!q.empty()){
g=q.front();
q.pop();
for(int i=0;i<4;i++){
a=g.x+dx[i];
b=g.y+dy[i];
if(a>=0&&a<m&&b>=0&&b<n&&str[a][b]!='#'&&!arr[a][b]){
arr[a][b]=1;
if(str[a][n]=='E'){
ans=1;
cout<<"可以通过"<<endl;
return ;
}
t.x=a;
t.y=b;
t.z=g.z+1;
q.push(t);
}
}
}
}
int main(){
ans=0;
cin>>m>>n;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++){
cin>>str[i][j];
if(str[i][j]=='S')x=i,y=j;
}
bfs();
if(ans==0)cout<<"不可以通过"<<endl;
return 0;
}
```
by DFs_YYDS @ 2024-04-25 13:26:33
@[2345A](/user/565070) 这个不需要求最短路径,dfs其实也行,就是慢了点
by DFs_YYDS @ 2024-04-25 13:27:57
@[DFs_YYDS](/user/1119406) 谢了
by 2345A @ 2024-04-25 13:28:17
@[2345A](/user/565070) 另外建议你level越高地雷就更多些(
by liuruiqing @ 2024-04-25 13:28:57
#墙壁 .空地 a起点 r终点```
#include<bits/stdc++.h>
using namespace std;
struct Node{
int x,y,cost;
}now;
int vis[1010][1010];
queue<Node>sum;
int xx,yy,ex,ey,fx,fy,n,m;
int dx[9]={0,0,0,-1,1};
int dy[9]={0,-1,1,0,0};
void bfs(Node x){
sum.push(x);
vis[x.x][x.y]=1;
while(!sum.empty()){
Node b=sum.front();
sum.pop();
if(b.x==ex&&b.y==ey){
cout<<b.cost;
exit(0);
}
for(int i=1;i<=4;i++){
Node t;
t.x=b.x+dx[i];t.y=b.y+dy[i];t.cost=b.cost+1;
if(t.x>=1&&t.y>=1&&t.x<=n&&t.y<=m&&vis[t.x][t.y]==0){
vis[t.x][t.y]=1;
sum.push(t);
}
}
}
cout<<"NO ANSWER";
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char oo;
cin>>oo;
if(oo=='#')vis[i][j]=1;
if(oo=='a')ex=i,ey=j;
if(oo=='r')fx=i,fy=j;
}
}
now.x=fx,now.y=fy,now.cost=0;
bfs(now);
return 0;
}
```
by xiaobaozi @ 2024-04-25 13:29:11
@[2345A](/user/565070) 给个关注吧QWQ
by DFs_YYDS @ 2024-04-25 13:29:22
不用,应该特判起终点周围一下就可以
by fanjiayu666 @ 2024-04-25 13:29:53
@[DFs_YYDS](/user/1119406) 关注了
by 2345A @ 2024-04-25 13:30:19
@[fanjiayu666](/user/1251774)
假如用地雷围成只有一条路,阁下又该如何应对?
by DFs_YYDS @ 2024-04-25 13:34:31
好像是,但几率小
by fanjiayu666 @ 2024-04-25 13:36:25