因为要求的是最少的时间,很明显的是一个利用优先队列的bfs的题目,题目很一般。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
#include"iostream"#include"algorithm"#include"stdio.h"#include"string.h"#include"cmath"#include"queue"#define mx 205using namespace std;int n,m,sx,sy,ex,ey;int dir[4][2]={ { 0,1},{ 0,-1},{-1,0},{ 1,0}};char map1[mx][mx];struct node{ int x,y,steps; friend bool operator<(node a,node b) { return b.steps=0&&x =0&&y q; q.push(cur); while(!q.empty()) { cur=q.top(); q.pop(); if(cur.x==ex&&cur.y==ey){cout< < >map1[i][j]; if(map1[i][j]=='r') {sx=i;sy=j;map1[i][j]='#';} else if(map1[i][j]=='a') {ex=i;ey=j;map1[i][j]='.';} } bfs(); } return 0;}