HDU 1242 Rescue 营救天使
Description
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
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
# .a #..r.
#..#x... ..#..#.#
#...##.. .#...... ........
Sample Output
- #include<cstdio>
- #include<string.h>
- #include<queue>
- using namespace std;
- int m,n,i,j,ans,map[][],ex,ey,bx,by;
- int dx[]={-,,,};
- int dy[]={,,-,};
- char str[];
- struct stu
- {
- int x,y,step;
- bool friend operator <(stu a,stu b)
- {
- return a.step>b.step;
- }
- }st;
- int bfs()
- {
- priority_queue<stu>que;
- int x,y,i,time;
- stu next;
- st.x=bx;
- st.y=by;
- st.step=;
- que.push(st);
- while(!que.empty())
- {
- st=que.top();
- que.pop();
- time=st.step;
- x=st.x;
- y=st.y;
- for(i=;i<;i++)
- {
- st.x=x+dx[i];
- st.y=y+dy[i];
- if(st.x>= &&st.y>=&&st.x<m&&st.y<m&&map[st.x][st.y]!=)
- {
- if(st.x == ex && st.y == ey)
- {
- return time+;
- }
- if(map[st.x][st.y] == )
- {
- st.step=time+;
- }
- else
- {
- st.step=time+;
- }
- map[st.x][st.y]=;
- que.push(st);
- }
- }
- }
- return ;
- }
- int main()
- {
- while(scanf("%d %d",&m,&n)!=EOF)
- {
- memset(map,,sizeof(map));
- for(i = ; i < m ; i++)
- {
- scanf("%s",&str);
- for(j = ;j < n ; j++)
- {
- if(str[j] == '.')
- {
- map[i][j]=;
- }
- if(str[j] == 'x')
- {
- map[i][j]=;
- }
- if(str[j] == 'a')
- {
- map[i][j]=;
- ex=i;
- ey=j;
- }
- if(str[j] == 'r')
- {
- map[i][j]=;
- bx=i;
- by=j;
- }
- }
- }
- /* for( i = 0 ; i < m ; i++)
- {
- for(j =0 ; j < n ; j++)
- {
- printf("%d ",map[i][j]);
- if(j == n-1)
- {
- printf("\n");
- }
- }
- } */
- map[bx][by]=;
- ans=bfs();
- if(ans)
- printf("%d\n",ans);
- else
- printf("Poor ANGEL has to stay in the prison all his life.\n");
- }
- }
HDU 1242 Rescue 营救天使的更多相关文章
- hdu 1242 Rescue
题目链接:hdu 1242 这题也是迷宫类搜索,题意说的是 'a' 表示被拯救的人,'r' 表示搜救者(注意可能有多个),'.' 表示道路(耗费一单位时间通过),'#' 表示墙壁,'x' 代表警卫(耗 ...
- 杭电 HDU 1242 Rescue
http://acm.hdu.edu.cn/showproblem.php?pid=1242 问题:牢房里有墙(#),警卫(x)和道路( . ),天使被关在牢房里位置为a,你的位置在r处,杀死一个警卫 ...
- hdu 1242:Rescue(BFS广搜 + 优先队列)
Rescue Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- hdu - 1242 Rescue && hdu - 2425 Hiking Trip (优先队列+bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1242 感觉题目没有表述清楚,angel的朋友应该不一定只有一个,那么正解就是a去搜索r,再用普通的bfs就能过了 ...
- hdu 1242 Rescue(bfs)
此刻再看优先队列,不像刚接触时的那般迷茫!这也许就是集训的成果吧! 加油!!!优先队列必须要搞定的! 这道题意很简单!自己定义优先级别! +++++++++++++++++++++++++++++++ ...
- HDU 1242 Rescue(优先队列)
题目来源: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: Problem Description Angel was caught by ...
- HDU 1242 Rescue(BFS+优先队列)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: Problem Description Angel was caught by t ...
- HDU 1242 -Rescue (双向BFS)&&( BFS+优先队列)
题目链接:Rescue 进度落下的太多了,哎╮(╯▽╰)╭,渣渣我总是埋怨进度比别人慢...为什么不试着改变一下捏.... 開始以为是水题,想敲一下练手的,后来发现并非一个简单的搜索题,BFS做肯定出 ...
- HDU 1242 Rescue (BFS(广度优先搜索))
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
随机推荐
- 跟我一起玩Win32开发(23):渐变颜色填充
GradientFill函数可以对特定的矩形区域或者三角形区域进行渐变颜色的填充.我们先来看看GradientFill函数到底长得什么样子,帅不帅. BOOL GradientFill( _In_ ...
- [BZOJ4064/Cerc2012]The Dragon and the knights
Description 与当地鞋匠协会发生冲突的瓦维尔城堡的龙决定将它的狩猎场移出克拉科夫以减少敌对的邻居数量.现在他正在给和平而宁静的Bytes王国带来灾难与恐怖. 在Bytes王国有n条河流,每一 ...
- 从一个n位数中选出m位按顺序组成新数并使其最大 || Erasing and Winning UVA - 11491
就是从n位数中取出n-d个数字按顺序排成一排组成一个新数使得其最大 算法: 从前往后确定每一位.找第i位时,要求后面留下d-i位的空间, 因此第i位应该从第i-1位原来位置+1到第d+i位寻找 用线段 ...
- vue项目node升级后,node-saas报错解决办法
ERROR in ./node_modules/_extract-text-webpack-plugin@3.0.2@extract-text-webpack-plugin/dist/loader.j ...
- 123 Best Time to Buy and Sell Stock III 买卖股票的最佳时机 III
假设你有一个数组,它的第 i 个元素是一支给定的股票在第 i 天的价格.设计一个算法来找到最大的利润.你最多可以完成两笔交易.注意:你不可同时参与多笔交易(你必须在再次购买前出售掉之前的股票).详见: ...
- P1847 轰炸II
题目背景 本题为轰炸数据加强版 题目描述 一个城市遭到了M次轰炸,每次都炸了一个每条边都与边界平行的矩形 在轰炸后,有N个关键点,指挥官想知道,它们有没有受到过轰炸,如果有,被炸了几次,最后一次是第几 ...
- 【ADO.NET】 使用通用数据库操作类Database (SQL Server)
一.Web.config配置 <connectionStrings> <add name="constr_name" connectionString=" ...
- 构建微服务开发环境6————利用npm安装前端框架
[内容指引] 安装JQuery组件: 安装BootStrap前端框架; 安装AngularJs前端框架: 安装angular动画模块: 安装angular的ui-router模块. 一.进入下载的目标 ...
- 最新版kubernetesV1.14.1集群一键自动部署脚本
部署命令如下:详情及注意事项请看README.md git clone https://github.com/luckman666/deploy_Kubernetes-v1.14.1.git cd d ...
- npm安装使用及vue脚手架安装
公司在前端用vue开发项目,那就学习下啦,第一步,在安装vue-devtools过程中,npm作为官方manual installtion方式,肯定必不可少. NPM是随同NodeJS一起安装的包管理 ...