zoj1649-Rescue(priority_queue)

#include
#include
using namespace std;
char maze[201][201];//迷宫
const int pmove[4][2]={{0,1},{0,-1},{-1,0},{1,0}};//移动
int n;//多少行
int m;//多少列
int sx,sy,ex,ey;
int prison();
struct Node
{
	friend bool operator < (Node a,Node b)
	{
		return a.step>b.step;
	}
	int x,y,step;
};
int main()
{
	int i,j,result;
	while(cin>>n>>m)
	{
	for(i=0;i>maze[i][j];
			if(maze[i][j]=='r')
			{
				sx=j;
				sy=i;
				maze[i][j]='#';
				continue;
			}
			if(maze[i][j]=='a')
			{
				ex=j;
				ey=i;
				continue;
			}
		}
		result=prison();
		if(result)
			cout< que;
	Node now,temp;
	int v;
	now.x=sx;
	now.y=sy;
	now.step=0;
	que.push(now);
	while(!que.empty())
	{
		temp=que.top();
		que.pop();
		for(v=0;v<4;v++)
		{
			now.x=temp.x+pmove[v][0];
			now.y=temp.y+pmove[v][1];
			if(now.x==ex&&now.y==ey)
				return temp.step+1;
			if(now.x<0||now.y<0||now.x>m-1||now.y>n-1)
				continue;
			if(maze[now.y][now.x]!='#')
			{
				if(maze[now.y][now.x]=='.')
					now.step=temp.step+1;
				else
					now.step=temp.step+2;
				que.push(now);
				maze[now.y][now.x]='#';
			}
		}
	}
	return 0;
}

你可能感兴趣的:(ACM)