Rescue

Rescue

真恶心,还是犯低级错误,定义mapp时用成int 去了,卡了好久,另外这题需要注意的就是需要比较大小;


// File Name: hdu1242bfs.cpp
// Author: rudolf
// Created Time: 2013年04月22日 星期一 20时27分33秒

#include<iostream>
#include<memory.h>
#include<queue>
#include<string.h>
#include<stdio.h>
using namespace std;
const int maxn=205;
char mapp[maxn][maxn];
int used[maxn][maxn];
int dis[4][2]={1,0,-1,0,0,1,0,-1};
int n,m;
int x1,y1,x2,y2;

bool flag;
struct node
{
	friend bool operator<(node a,const node b)
	{
		return a.step>b.step;
	}
	int x,y,step;
}cur,next;

int main()
{
	int i,j;
	while(cin>>n>>m)
	{
	//	//memset(mapp,0,sizeof(mapp));
		for(i=0;i<n;i++)
		{
			//getchar();
			for(j=0;j<m;j++)
			{
				cin>>mapp[i][j];
				used[i][j]=10000000;
				if(mapp[i][j]=='r')
				{
					x1=i;
					y1=j;
				}
				if(mapp[i][j]=='a')
				{
					x2=i;
					y2=j;
				}	
			}
		}
		flag=false;
		priority_queue<node> Q;
		//node cur,next;
		cur.x=x1;
		cur.y=y1;
		cur.step=0;
		Q.push(cur);
	//	used[x1][y1]=1;
		while(!Q.empty())
		{
			cur=Q.top();
			Q.pop();
			if(cur.x==x2&&cur.y==y2)
			{
				flag=true;
				break;
			}
				for(i=0;i<4;i++)
				{
					next.x=cur.x+dis[i][0];
					next.y=cur.y+dis[i][1];
					if(next.x>=0&&next.x<n&&next.y>=0&&next.y<m&&mapp[next.x][next.y]!='#')
					{
						if(mapp[next.x][next.y]=='x')
							next.step=cur.step+2;
						else
							next.step=cur.step+1;;
						if(next.step>=used[next.x][next.y])
							continue;
						used[next.x][next.y]=next.step;
						Q.push(next);
					}
				}
			}	
		if(flag)
			cout<<cur.step<<endl;
		else
			cout<<"Poor ANGEL has to stay in the prison all his life."<<endl;
	}
return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值