HDU2425:Hiking Trip(简单bfs,优先队列实现)
题目: 传送门
题意很简单就不解释了,水题一道。
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
typedef __int64 ll;
#define inf 0x3f3f3f3f
#include <math.h>
#include <queue>
using namespace std;
struct node
{
int x,y,ans;
bool operator<(const node &a)const //从小到大排序
{
return ans>a.ans;
}
};
node st,ff;
int n,m,P,S,T,s,e,s2,e2,v[][];
char a[][];
int fx[]= {,-,,};
int fy[]= {,,,-};
int main()
{
int sum,K=;
while(scanf("%d%d",&n,&m)!=EOF)
{
priority_queue<node>q;
while(!q.empty()) q.pop();
sum=-;
scanf("%d%d%d",&P,&S,&T);
for(int i=; i<n; i++)
scanf("%s",a[i]);
scanf("%d%d%d%d",&s,&e,&s2,&e2);
memset(v,,sizeof(v));
st.x=s,st.y=e,st.ans=;
v[s][e]=;
q.push(st);
while(!q.empty())
{
ff=q.top();
q.pop();
if(ff.x==s2&&ff.y==e2)
{
sum=ff.ans;
break;
}
for(int i=; i<; i++)
{
st.x=ff.x+fx[i];
st.y=ff.y+fy[i];
if(v[st.x][st.y]==&&a[st.x][st.y]!='@')
{
if(a[st.x][st.y]=='T')
{
st.ans=ff.ans+T;
v[st.x][st.y]=;
q.push(st);
}
else if(a[st.x][st.y]=='.')
{
st.ans=ff.ans+S;
v[st.x][st.y]=;
q.push(st);
}
else if(a[st.x][st.y]=='#')
{
st.ans=ff.ans+P;
v[st.x][st.y]=;
q.push(st);
}
}
}
}
printf("Case %d: %d\n",++K,sum); }
return ;
}
HDU2425:Hiking Trip(简单bfs,优先队列实现)的更多相关文章
- hdu 2425 Hiking Trip (bfs+优先队列)
Problem Description Hiking in the mountains is seldom an easy task for most people, as it is extreme ...
- hdu 2425 Hiking Trip
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2425 Hiking Trip Description Hiking in the mountains ...
- hdu1839(二分+优先队列,bfs+优先队列与spfa的区别)
题意:有n个点,标号为点1到点n,每条路有两个属性,一个是经过经过这条路要的时间,一个是这条可以承受的容量.现在给出n个点,m条边,时间t:需要求在时间t的范围内,从点1到点n可以承受的最大容量... ...
- BFS+优先队列+状态压缩DP+TSP
http://acm.hdu.edu.cn/showproblem.php?pid=4568 Hunter Time Limit: 2000/1000 MS (Java/Others) Memo ...
- HDU 1242 -Rescue (双向BFS)&&( BFS+优先队列)
题目链接:Rescue 进度落下的太多了,哎╮(╯▽╰)╭,渣渣我总是埋怨进度比别人慢...为什么不试着改变一下捏.... 開始以为是水题,想敲一下练手的,后来发现并非一个简单的搜索题,BFS做肯定出 ...
- LightOJ 1012 简单bfs,水
1.LightOJ 1012 Guilty Prince 简单bfs 2.总结:水 题意:迷宫,求有多少位置可去 #include<iostream> #include<cstr ...
- POJ3185(简单BFS,主要做测试使用)
没事做水了一道POJ的简单BFS的题目 这道题的数据范围是20,所以状态总数就是(1<<20) 第一次提交使用STL的queue,并且是在队首判断是否达到终点,达到终点就退出,超时:(其实 ...
- POJ 1724 ROADS(BFS+优先队列)
题目链接 题意 : 求从1城市到n城市的最短路.但是每条路有两个属性,一个是路长,一个是花费.要求在花费为K内,找到最短路. 思路 :这个题好像有很多种做法,我用了BFS+优先队列.崔老师真是千年不变 ...
- 【POJ 3669 Meteor Shower】简单BFS
流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...
随机推荐
- 扩展KMP - HDU 4333 Revolving Digits
Revolving Digits Problem's Link Mean: 给你一个字符串,你可以将该字符串的任意长度后缀截取下来然后接到最前面,让你统计所有新串中有多少种字典序小于.等于.大于原串. ...
- phpstorm 中文版 支持BUG调试 IDE
下载地址:http://dx2.7down.net/soft/P/phpstorm8_cn.zip
- 【BZOJ】1622: [Usaco2008 Open]Word Power 名字的能量(dp/-模拟)
http://www.lydsy.com/JudgeOnline/problem.php?id=1622 这题我搜的题解是dp,我也觉得是dp,但是好像比模拟慢啊!!!! 1400ms不科学! 设f[ ...
- thinkphp nginx pathinfo模式支持
最近一个项目中使用了ThinkPHP做为开发框架,URL上我们使用了PATHINFO模式,但是Nginx默认是不支持PATHINFO的,需要进行手动配置才可以,于是我们按照了以下方法进行了Nginx的 ...
- hdu 2612:Find a way(经典BFS广搜题)
Find a way Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Apache版Phoenix的安装(图文详解)
不多说,直接上干货! 写在前面的话 我这里,三个节点的bigdata集群.分别为master.slave1和slave2. 1.Phoenix的下载 我的HBase版本是hbase-0.98.19. ...
- python里的生成器
author:headsen chen date:2018-03-22 10:59:46 notice:This article created by headsen chen himself and ...
- android how to deal with data when listview refresh
如何解决listview数据刷新,下拉刷新,上拉加载更多时,图片不闪烁. 在Activity的onResume()方法中将adaper和listView重新再绑定一次. listView.setAda ...
- Vue基础-匿名插槽与作用域插槽的合并和覆盖行为
Vue 测试版本:Vue.js v2.5.13 Vue 文档: <slot> 元素可以用一个特殊的特性 name 来进一步配置如何分发内容.多个插槽可以有不同的名字.具名插槽将匹配内容片段 ...
- Ubuntu16.4下RStudio1.1.447 中文输入问题的解决方案
Ubuntu16.4下RStudio1.1.447 中文输入问题的解决方案参照:https://blog.csdn.net/matteoshenl/article/details/78603528 R ...