HDU 1242——Rescue(优先队列)】的更多相关文章

题目链接:hdu 1242 这题也是迷宫类搜索,题意说的是 'a' 表示被拯救的人,'r' 表示搜救者(注意可能有多个),'.' 表示道路(耗费一单位时间通过),'#' 表示墙壁,'x' 代表警卫(耗费两个单位时间通过),然后求出 'r' 能找到 'a' 的最短时间,找不到输出 "…………"(竟然在这里也 wa 了一发 -.-||).很明显是广搜了,因为 'r' 可能有多个,所以我们反过来从 'a' 开始搜,每次搜到 'r' 都更新最小时间值(很重要的一个转换!).可是这题因为通过 '…
http://acm.hdu.edu.cn/showproblem.php?pid=1242 感觉题目没有表述清楚,angel的朋友应该不一定只有一个,那么正解就是a去搜索r,再用普通的bfs就能过了. 但是别人说要用优先队列来保证时间最优,我倒是没明白,步数最优跟时间最优不是等价的吗?就算士兵要花费额外时间,可是既然先到了目标点那时间不也一定是最小的? 当然用优先队列+ a去搜索r是最稳妥的. #include <cstdio> #include <cstring> #inclu…
题目来源: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: 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 pris…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: 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…
题目链接:Rescue 进度落下的太多了,哎╮(╯▽╰)╭,渣渣我总是埋怨进度比别人慢...为什么不试着改变一下捏.... 開始以为是水题,想敲一下练手的,后来发现并非一个简单的搜索题,BFS做肯定出事...后来发现题目里面也有坑 题意是从r到a的最短距离,"."相当时间单位1,"x"相当时间单位2,求最短时间 HDU 搜索课件上说,这题和HDU1010相似,刚開始并没有认为像剪枝,就改用  双向BFS   0ms  一Y,爽! 网上查了一下,神牛们居然用BFS+优…
Rescue Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 14   Accepted Submission(s) : 7 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Angel was caught by the MOLIGPY…
Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 24205    Accepted Submission(s): 8537 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is d…
题目 /******************以下思路来自百度菜鸟的程序人生*********************/ bfs即可,可能有多个’r’,而’a’只有一个,从’a’开始搜,找到的第一个’r’即为所求 需要注意的是这题宽搜时存在障碍物,遇到’x’点是,时间+2,如果用普通的队列就 并不能保证每次出队的是时间最小的元素,所以要用优先队列,第一次用优先队列,还不熟练哇 优先队列(priority_queue)的基本操作: empty(); 队列为空返回1 pop();   出队 push(…
题意: 一个天使a被关在迷宫里,她的很多小伙伴r打算去救她.求小伙伴就到她须要的最小时间.在迷宫里有守卫.打败守卫须要一个单位时间.假设碰到守卫必须要杀死他 思路: 天使仅仅有一个,她的小伙伴有非常多,所以能够让天使找她的小伙伴,一旦找到小伙伴就renturn.时间小的优先级高.优先队列搞定 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include&l…
题意:X代表卫兵,a代表终点,r代表起始点,.代表路,#代表墙,走过.要花费一秒,走过x要花费2秒,求从起点到终点的最少时间. 析:一看到样例就知道是BFS了吧,很明显是最短路径问题,不过又加了一个条件——时间,所以我们用优先队列去优先获取时间短的路径,总体实现起来没有太大难度. 代码如下: #include <iostream> #include <cstdio> #include <vector> #include <set> #include <…
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: approa…
此刻再看优先队列,不像刚接触时的那般迷茫!这也许就是集训的成果吧! 加油!!!优先队列必须要搞定的! 这道题意很简单!自己定义优先级别! +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ =================================================================================== +++++++++++++…
http://acm.hdu.edu.cn/showproblem.php?pid=1242 问题:牢房里有墙(#),警卫(x)和道路( . ),天使被关在牢房里位置为a,你的位置在r处,杀死一个警卫要一秒钟,每走一步要一秒钟,求最短时间救出天使,不能救出则输出:Poor ANGEL has to stay in the prison all his life.  求最短路径,果断广搜BFS 限制及剪枝: 1.墙不能走,不能离开牢房范围 2.杀死一个警卫要多花一秒钟 3.当前步骤大于等于最短时间…
题目链接 ZOJ链接 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…
Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12927    Accepted Submission(s): 4733 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is d…
Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 29263    Accepted Submission(s): 10342 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is…
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12441 Accepted Submission(s): 4551 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is descri…
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: approa…
题目链接 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: a…
翻出以前的代码看看 题意:走迷宫,遇到敌人要花一分钟. #include<iostream> #include<queue> using namespace std; char map[205][205]; int N = 999999999; int dir[4][2]={{0,1},{1,0},{-1,0},{0,-1}}; int n,m; struct node { int x; int y; int step; friend bool operator<(node…
第一次用容器做的BFS题目,题目有个地方比较坑,就是遍历时的方向,比如上下左右能AC,右上左下就WA #include <stdio.h> #include <string.h> #include <iostream> #include <queue> using namespace std; char map[205][205]; int x_begin,y_begin,flag,n,m; int v[205][205],d[4][2] = { {-1,0…
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…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目大意:多个起点到一个终点,普通点耗时1,特殊点耗时2,求到达终点的最少耗时. 解题思路: 如果没有特殊点,就是普通BFS. 由于特殊点的介入,所以BFS树的同一深度,各个点的值可能不同.所以使用优先队列,先取出值小的搜. 搜到的第一个符合条件的结果肯定是最小的,break. 注意有多个起点,所以先记录下所有起点,依次BFS找最小. #include "cstdio" #incl…
看题传送门: ZOJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649 HDU http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目大意初始位置在r,要求到达a的地点,地图上"."通过需要1s,"x"代表守卫,通过耗时2s,"#"不能走. BFS的应用. BFS求最短路径的原理是每一次向外扩张一格,(就像树的层次遍历一样…
找到朋友的最短时间 Sample Input7 8#.#####. //#不能走 a起点 x守卫 r朋友#.a#..r. //r可能不止一个#..#x.....#..#.##...##...#.............. Sample Output13 bfs+优先队列 #include <iostream> #include <cstring> #include <cstdio> #include <queue> using namespace std;…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2822 题目大意:X消耗0,.消耗1, 求起点到终点最短消耗 解题思路: 每层BFS的结点,优先级不同,应该先搜cost小的.直接退化为最短路问题. 优先队列优化. 卡输入姿势.如果O(n^2)逐个读的话会T掉.要用字符串读一行. #include "cstdio" #include "queue" #include "cstring" using…
Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19985    Accepted Submission(s): 7110 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is d…
Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 521    Accepted Submission(s): 217   Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is d…
经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线,并在风景秀美的诸暨市浬浦镇陶姚村买了个房子,开始安度晚年了. 这样住了一段时间,徐总对当地的交通还是不太了解.有时很郁闷,想去一个地方又不知道应该乘什么公交车,在什么地方转车,在什么地方下车(其实徐总自己有车,却一定要与民同乐,这就是徐总的性格). 徐总经常会问蹩脚的英文问路:“Can you help me?”.看着他…
http://acm.hdu.edu.cn/showproblem.php?pid=1509 裸的优先队列的应用,输入PUT的时候输入名字,值和优先值进队列,输入GRT的时候输出优先值小的名字和对应的值 注意的是优先级一样的时候输出顺序在前的 #include<cstdio> #include<cstring> #include<queue> using namespace std; struct point { int val,odr,num; ]; bool ope…