//bfs+优先队列#include#include #include using namespace std;const int ROW = 201;const int COL = 201;const int DIRS = 4;char map[ROW][COL];int dir[DIRS][2] = {-1,0,0,1,1,0,0,-1};struct priNode { int x, y, time; friend bool operator < (priNode a, priNode b) { return a.time > b.time; }};bool inMap(int pi, int pj, int row, int col);int bfs(int ai, int aj, int row, int col, int *ans);int main(void) { int n, m; int i, j; int ai, aj; while (scanf("%d%d", &n, &m) != EOF) { for (i=0; i =0 && pi =0 && pj < col);}int bfs(int ai, int aj, int row, int col, int *ans) { int i; priNode now, next; priority_queue
Q; now.x = ai; now.y = aj; now.time = 0; Q.push(now); map[ai][aj] = '#'; while (!Q.empty()) { now = Q.top(); Q.pop(); if (map[now.x][now.y] == 'r') { *ans = now.time; return 1; } for (i=0; i