#include <iostream>
#include <queue>
using namespace std;
int n, m;
const int MAX = 205;
char a[MAX][MAX], map[MAX][MAX];
int dir[4][2] = {
{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
struct node
{
int x, y, step;
};
void bfs()
{
int i, j;
struct node cur, next, end;
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
{
if(a[i][j] == 'r')
{
cur.x = i;
cur.y = j;
cur.step = 0;
}
if(a[i][j] == 'a')
{
end.x = i;
end.y = j;
}
}
if(cur.x == end.x && cur.y == end.y)
{
cout << 0 << endl;
return;
}
queue<node> q;
q.push(cur);
while(!q.empty())
{
cur = q.front();
q.pop();
for(i = 0; i < 4; i++)
{
next.x = cur.x + dir[i][0];
next.y = cur.y + dir[i][1];
next.step = cur.step + 1;
if(next.x == end.x &
HDU 1242 简单bfs
最新推荐文章于 2017-10-29 10:24:26 发布
![](https://img-home.csdnimg.cn/images/20240611030827.png)