hdu 2425 Hiking Trip (bfs+优先队列)
You've obtained the area Green's in as an R * C map. Each grid in the map can be one of the four types: tree, sand, path, and stone. All grids not containing stone are passable, and each time, when Green enters a grid of type X (where X can be tree, sand or path), he will spend time T(X). Furthermore, each time Green can only move up, down, left, or right, provided that the adjacent grid in that direction exists.
Given Green's current position and his destination, please determine the best path for him.
There is a blank line after each test case. Input ends with End-of-File.
1 2 10
T...TT
TTT###
TT.@#T
..###@
0 1 3 0
4 6
1 2 2
T...TT
TTT###
TT.@#T
..###@
0 1 3 0
2 2
5 1 3
T@
@.
0 0 1 1
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
int n,m;
int vp,vs,vt;
int k1,k2,e1,e2;
char data[][];
int visit[][];
int to[][]={{,},{-,},{,},{,-}}; struct node
{
int x,y;
int step;
friend bool operator < (node a,node b)
{
return a.step>b.step;
}
}; int go(int i,int j)
{
if(<=i&&i<n&&<=j&&j<m&&data[i][j]!='@'&&visit[i][j]==)
return ;
else return ;
} int bfs()
{
node st,ed;
priority_queue<node> q;
st.x=k1;
st.y=k2;
st.step=;
q.push(st);
memset(visit,,sizeof(visit));
visit[k1][k2]=;
while(!q.empty())
{
st=q.top();
q.pop();
if(st.x==e1&&st.y==e2)
{
cout<<st.step<<endl;
return ;
}
for(int i=;i<;i++)
{
ed.x=st.x+to[i][];
ed.y=st.y+to[i][];
if(go(ed.x,ed.y))
{
visit[ed.x][ed.y]=;
if(data[ed.x][ed.y]=='T')
ed.step=st.step+vt;
if(data[ed.x][ed.y]=='.')
ed.step=st.step+vs;
if(data[ed.x][ed.y]=='#')
ed.step=st.step+vp;
q.push(ed);
}
}
}
cout<<"-1"<<endl;
return ;
} int main()
{
int k=;
while(cin>>n>>m)
{
k++;
cin>>vp>>vs>>vt;
for(int i=;i<n;i++)
for(int j=;j<m;j++)
cin>>data[i][j];
cin>>k1>>k2>>e1>>e2;
cout<<"Case "<<k<<": ";
bfs();
}
return ;
}
hdu 2425 Hiking Trip (bfs+优先队列)的更多相关文章
- hdu 2425 Hiking Trip
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2425 Hiking Trip Description Hiking in the mountains ...
- hdu - 1242 Rescue && hdu - 2425 Hiking Trip (优先队列+bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1242 感觉题目没有表述清楚,angel的朋友应该不一定只有一个,那么正解就是a去搜索r,再用普通的bfs就能过了 ...
- HDU2425:Hiking Trip(BFS+优先队列)
给出一个地图,地图有四种路面,经过每种路面花费的时间不同,问从起点到终点所花费的最少时间是多少 把到各个点的花费存入队列中,然后弹出,即可得到最小 Sample Input 4 6 1 2 10 T. ...
- HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)
题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...
- HDU 1242 Rescue (BFS+优先队列)
题意:X代表卫兵,a代表终点,r代表起始点,.代表路,#代表墙,走过.要花费一秒,走过x要花费2秒,求从起点到终点的最少时间. 析:一看到样例就知道是BFS了吧,很明显是最短路径问题,不过又加了一个条 ...
- 2015多校第6场 HDU 5360 Hiking 贪心,优先队列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意:给定n个人,现在要邀请这些人去远足,但每个人同意邀请的条件是当前已经同意去远足的人数c必须 ...
- HDU 5360——Hiking——————【贪心+优先队列】
Hiking Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- hdu 5040 Instrusive【BFS+优先队列】
11733274 2014-09-26 12:42:31 Accepted 5040 62MS 1592K 4848 B G++ czy 先转一个优先队列的用法: http://www.cppblog ...
- hdu.1254.推箱子(bfs + 优先队列)
推箱子 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
随机推荐
- 面试题-JDBC
1.什么是JDBC? JDBC是允许用户在不同数据库之间做选择的一个抽象层.JDBC允许开发者用JAVA写数据库应用程序,而不需要关心底层特定数据库的细节. 2.解释下驱动(Driver)在JDBC中 ...
- POJ 3507 Judging Olympia
小技巧 判断 全部为零 用sign和所有元素依次取或 排除最大项和最小项 直接排序后取中间的四个元素 http://poj.org/problem?id=3507 1 #include <ios ...
- 【转】判断URL是否能够访问
import urllib2 def file_exists(url): request = urllib2.Request(url) request.get_method = lambda : 'H ...
- C# IDisposable的理解
C#里可以嵌入非托管代码,这就涉及到了这些代码资源的释放.以前总是看到别人的代码里那么写,也没有好好想想为什么,今天看了书,总结一下. 资源释放分为两种: 托管的 非托管的 两者的释放方式不一致: 没 ...
- HDU 5877 Weak Pair
$dfs$序,线段树. 可以统计每一个节点作为$root$的子树上对答案的贡献,可以将树转换成序列.问题就变成了一段区间上求小于等于某个值的数有几个.用线段树记录排好序之后的区间序列,询问的时候,属于 ...
- Python学习笔记——基础篇【第七周】———进程、线程、协程篇(socket基础)
http://www.cnblogs.com/wupeiqi/articles/5040823.htmlhttp://i.cnblogs.com/EditPosts.aspx?postid=55437 ...
- c# 索引器方法
索引器方法允许我们构建能够以类似访问数组的语法来访问内部子类型的自定义类型 在语法上索引器方法和属性的定义很类似,一样是使用get,set,不同的是索引器是使用this[]创建的. 一个简单的索引器代 ...
- 批量修改安卓apk包名
1.准备工作 1.1 反编译工具apktool下载 1.2 java, android SDK安装 1.2 python安装 2.反编译现有包 apktool.bat d test.apk 3. 直接 ...
- 关于reportng生成的测试报告不按测试执行顺序的解决办法
需要修改TestResultComparator类的源码,源码自己去reportng官网http://reportng.uncommons.org/下载,因为reportng默认是按字母先后顺序进行排 ...
- Winform 无边框窗口移动自定义边框粗细颜色
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...