文章
56
粉丝
0
获赞
179
访问
3.8k
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
char mpt[maxn][maxn];
int vis[maxn][maxn];
const int mov[4][2] = { 0,1,1,0,0,-1,-1,0 };
int ans;
struct node {//current position and travel distance
int x;
int y;
int dis;
};
int bfs(int nx, int ny)
{
ans = -1;//default cant get out
memset(vis, 0, sizeof(vis));
queue<node> q;
q.push(node{ nx,ny,0 });
vis[nx][ny] = 1;
while (!q.empty())
{
node now = q.front();
q.pop();
if (mpt[now.x][now.y] == 'E')
{
ans = now.dis;
break;
}
for (int i = 0; i < 4; i++)
{
int mx = now.x + mov[i][0];
int my = now.y + mov[i][1];
if (mpt[mx][my] != 0 && mpt[mx][my] != '#' && vis[mx][my] == 0)
{
q.push(node{ mx,my,now.dis + 1 });
vis[mx][my] = 1;
}
}
}
return ans;
}
int main()
{
int H, W;
while (cin >> H >> W)
{
if (!H && !W)
break;
memset(mpt, 0, sizeof(mpt));
for ...
登录后发布评论
暂无评论,来抢沙发