博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu1242 优先队列+bfs
阅读量:6289 次
发布时间:2019-06-22

本文共 3171 字,大约阅读时间需要 10 分钟。

Rescue

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 22034    Accepted Submission(s): 7843

Problem Description
Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison.
Angel's friends want to save Angel. Their task is: approach Angel. We assume that "approach Angel" is to get to the position where Angel stays. When there's a guard in the grid, we must kill him (or her?) to move into the grid. We assume that we moving up, down, right, left takes us 1 unit time, and killing a guard takes 1 unit time, too. And we are strong enough to kill all the guards.
You have to calculate the minimal time to approach Angel. (We can move only UP, DOWN, LEFT and RIGHT, to the neighbor grid within bound, of course.)
 

 

Input
First line contains two integers stand for N and M.
Then N lines follows, every line has M characters. "." stands for road, "a" stands for Angel, and "r" stands for each of Angel's friend. 
Process to the end of the file.
 

 

Output
For each test case, your program should output a single integer, standing for the minimal time needed. If such a number does no exist, you should output a line containing "Poor ANGEL has to stay in the prison all his life." 
 

 

Sample Input
7 8 #.#####. #.a#..r. #..#x... ..#..#.# #...##.. .#...... ........
 

 

Sample Output
13
 

 

Author
CHEN, Xue
 

 

Source
 

 

Recommend
Eddy   |   We have carefully selected several similar problems for you:            
1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 7 struct Point 8 { 9 int x,y,t;10 bool operator < (const Point &a)const11 {12 return t>a.t;13 }14 };15 16 char map[205][205];17 Point start;18 int n,m;19 int diect[][2]={
{
1,0},{-1,0},{
0,1},{
0,-1}}; 20 21 int bfs()22 { 23 priority_queue
que;24 Point cur,next;25 int i,j;26 27 map[start.x][start.y]='#';28 que.push(start);29 while(!que.empty())30 {31 cur=que.top();32 que.pop();33 for(i=0;i<4;i++)34 {35 next.x=cur.x+diect[i][0]; 36 next.y=cur.y+diect[i][1]; 37 next.t=cur.t+1;38 if(next.x<0 || next.x>=n || next.y<0 || next.y>=m)39 continue;40 if(map[next.x][next.y]=='#')41 continue;42 if(map[next.x][next.y]=='r')43 return next.t;44 if(map[next.x][next.y]=='.')45 {46 map[next.x][next.y]='#';47 que.push(next);48 }49 else if(map[next.x][next.y]=='x')50 {51 map[next.x][next.y]='#';52 next.t++;53 que.push(next);54 }55 }56 }57 return -1;58 }59 60 int main()61 {62 int i,j,ans;63 char *p;64 while(scanf("%d %d",&n,&m)!=EOF)65 {66 for(i=0;i
View Code

 

转载于:https://www.cnblogs.com/cyd308/p/4817740.html

你可能感兴趣的文章
3.31
查看>>
类对象定义 二
查看>>
收费视频网站Netflix:用户到底想要“点”什么?
查看>>
MacOS High Sierra 12 13系统转dmg格式
查看>>
关于再次查看已做的多选题状态逻辑问题
查看>>
动态下拉菜单,非hover
查看>>
政府安全资讯精选 2017年第十六期 工信部发布关于规范互联网信息服务使用域名的通知;俄罗斯拟建立备用DNS;Google打击安卓应用在未经同意情况下收集个人信...
查看>>
简单易懂的谈谈 javascript 中的继承
查看>>
iOS汇编基础(四)指针和macho文件
查看>>
Laravel 技巧锦集
查看>>
Android 使用 ViewPager+RecyclerView+SmartRefreshLayout 实现顶部图片下拉视差效果
查看>>
Flutter之基础Widget
查看>>
写给0-3岁产品经理的12封信(第08篇)——产品运营能力
查看>>
ArcGIS Engine 符号自动化配置工具实现
查看>>
小程序 · 跳转带参数写法,兼容url的出错
查看>>
flutter error
查看>>
Flask框架从入门到精通之模型数据库配置(十一)
查看>>
10年重新出发
查看>>
2019年-年终总结
查看>>
聊聊elasticsearch的RoutingService
查看>>