HDU 2425 Hiking Trip(bfs+优先队列)

python音频信号分析 声音以具有诸如频率、带宽、分贝等参数的音频信号的形式表示,典型的音频信号可以表示为幅度和时间的函数 阅读详情

Description

Hikingin the mountains is seldom an easy task for most people, as it is extremelyeasy to get lost during the trip. Recently Green has decided to go on a hikingtrip. Unfortunately, half way through the trip, he gets extremely tired and soneeds to find the path that will bring him to the destination with the leastamount of time. Can you help him?

You'veobtained the area Green's in as an R * C map. Each grid in the map can be oneof the four types: tree, sand, path, and stone. All grids not containing stoneare passable, and each time, when Green enters a grid of type X (where X can betree, sand or path), he will spend time T(X). Furthermore, each time Green canonly move up, down, left, or right, provided that the adjacent grid in thatdirection exists.

GivenGreen's current position and his destination, please determine the best pathfor him.

 

Input

Thereare multiple test cases in the input file. Each test case starts with twointegers R, C (2 <= R <= 20, 2 <= C <= 20), the number of rows /columns describing the area. The next line contains three integers, V P, V S, VT (1 <= V P <= 100, 1 <= V S <= 100, 1 <= V T <= 100),denoting the amount of time it requires to walk through the three types of area(path, sand, or tree). The following R lines describe the area. Each of the Rlines contains exactly C characters, each character being one of the following:‘T’, ‘.’, ‘#’, ‘@’, corresponding to grids of type tree, sand, path and stone.The final line contains four integers, S R, S C, T R, T C, (0 <= S R < R,0 <= S C < C, 0 <= T R < R, 0 <= T C < C), representing yourcurrent position and your destination. It is guaranteed that Green's currentposition is reachable – that is to say, it won't be a '@' square.

Thereis a blank line after each test case. Input ends with End-of-File.

 

Output

Foreach test case, output one integer on one separate line, representing theminimum amount of time needed to complete the trip. If there is no way forGreen to reach the destination, output -1 instead.

 

SampleInput

4 6

1 210

T...TT

TTT###

TT.@#T

..###@

0 13 0

 

4 6

1 22

T...TT

TTT###

TT.@#T

..###@

0 13 0

 

2 2

5 13

T@

@.

0 01 1

 

SampleOutput

Case1: 14

Case2: 8

Case3: -1


题意:有一R行C列的矩形区域,不同单位区域分布着平路、沙路、树林和石头四种状态,石头不能走,经过其它三种状态的时间不同,给出人的起始位置和终止位置,求出人能花费的最少时间。

分析:这是一道明显的bfs求最短路径的题目,从起始位置依次遍历人能走的所有位置,用优先队列保存各个状态,遍历到终点位置后返回最少时间。题目很直接,没有什么wa点。下面附上代码。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
int r,c;
int vp,vs,vt;
int Move[4][2]={1,0,0,1,-1,0,0,-1};
int ans;
char s[25][25];
int sr,sc,tr,tc;
struct node  //创建结点,用x,y表示当前人的位置,num表示人当前所用时间。
{
int x,y,num; 
node(int xx=0,int yy=0,int nn=0):x(xx),y(yy),num(nn){}
friend bool operator<(const node &a,const node &b)
{
return a.num>b.num;
}
};
map<char,int>Map;

bool inx(int x)
{
return x>=0&&x<r;
}
bool iny(int y)
{
return y>=0&&y<c;
}
int bfs()
{
priority_queue<node>q;
s[sr][sc]='@';
q.push(node(sr,sc,Map[s[sr][sc]]));
//cout<<Map[s[sr][sc]]<<endl;
while(!q.empty())
{
node t=q.top(); q.pop();
if(t.x==tr&&t.y==tc) return t.num;
for(int i=0;i<4;i++)
{
int tx=t.x+Move[i][0];
int ty=t.y+Move[i][1];
if(inx(tx)&&iny(ty)&&s[tx][ty]!='@')
{
q.push(node(tx,ty,t.num+Map[s[tx][ty]]));
//cout<<Map[s[tx][ty]]<<endl;
s[tx][ty]='@';
}
}
}
return -1;
}
int main()
{
int T=1;
while(cin>>r>>c)
{
scanf("%d%d%d",&vp,&vs,&vt);
Map['#']=vp; Map['.']=vs; Map['T']=vt; Map['@']=0;
for(int i=0;i<r;i++)
scanf("%s",s[i]);
scanf("%d%d%d%d",&sr,&sc,&tr,&tc);
int ans=bfs();
printf("Case %d: %d\n",T++,ans);
}
return 0;
}

Allegro输出光绘文件规范 添加钻孔表的具体步骤为:1.通过屏幕右边的Visibility选项的Views列表,将Drill层打开2.将Visibility选项中的PIN和Via选项都选中,见下图所示: 参数设好之后关闭NC Drill/Parameters窗口,输出数控机床钻孔文件的命令菜单为:Manufacture=>NC=>NC Drill…,打开的窗口如下: 输出数控机床钻孔文件的具体步骤为: 上图是光绘输出的层控制窗口,还有一个窗口是输出参数的控制窗口,我们通过点击上图的第二个列表项General Parameters来 阅读详情

相关推荐

基于PI双闭环解耦控制的三相SVPWM电压型逆变器(3)--调制方法

阐述SPWM和SVPWM的原理以及实现方法

weixin_58670090的博客 6259

Hiking Trip(bfs+优先队列)

Hiking Trip Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1444    Accepted Submission(s): 628 Problem Description Hiking in the m

不会思考的机器 862

nacos3.1.0适配国产数据库

Nacos 3.1.0适配国产数据库指南 本文介绍了Nacos 3.1.0版本适配达梦数据库和人大金仓数据库的具体步骤。主要内容包括:添加达梦和人大金仓的JDBC驱动依赖,修改nacos-persistence模块的配置文件及相关Java类,以及打包和运行注意事项。文章特别指出3.1.0版本需要JDK17环境,并提供了解决常见问题的建议,如添加VM options配置和不同启动方式等。通过本文的配置指导,可以实现Nacos服务在国产数据库环境下的正常运行。

梦昼初的博客 1465

结构体内嵌比较函数bool operator < (const node &x) const {}

关于结构体内嵌比较函数: 一般情况下: struct node { int l,r; bool operator <(const node &a)const{ return r < a.r; } }a[maxn]; 直接写比较函数是裸的r表示当前的值,如果r<a.r,那么就是从小到大排序,但是优先队列的是相反的。 sort默认为从小到大排序,优先队列默认为从大到小。 struct node { int l,r;

Li5566123的博客 6774

AI时代,程序员何去何从?别慌,看完这篇你就明白了

AI时代程序员的发展方向 摘要:随着AI代码助手的普及,程序员行业面临变革。本文通过实际案例展示AI写代码的能力与局限:AI能生成基础功能代码(如RESTful API、数据处理脚本),但缺乏业务理解、系统设计和复杂逻辑处理能力。程序员的核心价值在于需求分析、架构设计、性能优化等高层能力。未来程序员应: 掌握AI工具提升效率 专注于创新和架构设计 培养业务理解能力 持续学习新技术 AI不会取代程序员,但会淘汰不会使用AI的程序员。建议开发者拥抱AI工具,将其作为助手而非威胁,聚焦高价值工作。

yunque_xianguang的博客 908

注意力机制模块:注意力机制新宠:EMA 注意力(高效多尺度注意力),即插即用,涨点明显

无降维成为共识:越来越多的研究者意识到,传统注意力机制的通道降维操作会造成不可逆的信息损失。EMA 提出的“保留每个通道信息”理念正在成为新一代注意力模块的设计标准。分组并行走向成熟:特征分组 + 并行处理的设计范式已在多个前沿架构中得到验证,兼顾了表达能力和计算效率。多尺度与跨空间融合:单纯的多尺度或单纯的跨空间交互都已无法满足复杂任务需求,两者的深度融合是当前的主流方向。边缘部署导向:2026 年的新论文越来越关注在资源受限设备上的高效运行,轻量化设计成为评估注意力模块的重要指标。

ZXSXJ的博客 948

2425 Hiking Trip

Hiking Trip Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1374    Accepted Submission(s): 607 Problem Description Hiking in the m

zxiaopp的专栏 689

【Java基础知识 1】Java入门级概述

优快云最强Java专栏,包含全部Java基础知识点、Java8新特性、Java集合、Java多线程、Java代码实例,理论结合实战,实现Java的轻松学习。

学Java,找哪吒 16万+

HDU 2425 Hiking Trip(bfs+优先队列)

Hiking Trip Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1582    Accepted Submission(s): 696 Problem Description Hiking in the mount

yasolx的博客 642

如何通过插值法计算cell delay?

插值法的公式:Z = A + B * X + C * Y + D * X * Y,其中X为input transition,Y为output load,A、B、C、D为四个参数,Z为delay值。从而得到Z=-0.086176 + 11.5493 * x + 0.65917 * y - 24.859 * x * y,当X=0.014930、Y=0.296311时,得到Z=0.1716ns。从而得到A = 0.08075,B = 3.47539,C = 0.04008,D = 0.01648。

芯冰乐 1076

CAPL编程规范与最佳实践

通过本文的学习,读者应该对CAPL编程规范与最佳实践有了初步的了解,并能够编写高质量的CAPL脚本。在实际项目中,CAPL的应用非常广泛,希望读者能够通过不断的学习和实践,掌握更多的CAPL技巧,提高自己的开发能力。

闲人编程的博客 1747

hdu 2425 Hiking Trip

BFS水题 Problem Description Hiking in the mountains is seldom an easy task for most people, as it is extremely easy to get lost during the trip. Recently Green has decided to go on a hiking trip

534

Jetson agx Orin 适配Xenomai4

例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。

xiaoning132的专栏 465

HDU-2425-Hiking Trip(优先队列+BFS)

Hiking Trip Problem Description Hiking in the mountains is seldom an easy task for most people, as it is extremely easy to get lost during the trip. Recently Green has decided to go on a hiking trip. ...

qq_43461168的博客 254

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

HDU2425:Hiking Trip(BFS+优先队列)

给出一个地图,地图有四种路面,经过每种路面花费的时间不同,问从起点到终点所花费的最少时间是多少 把到各个点的花费存入队列中,然后弹出,即可得到最小  Sample Input 4 6 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

阳光下的泡沫 540

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

HDU 2425-Hiking Trip(BFS+优先队列)

Hiking Trip Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1303    Accepted Submission(s): 576 Problem Description Hiking in the m

Orz~~Orz 1144

HDU2425 Hiking Trip(bfs+优先队列)

http://acm.hdu.edu.cn/showproblem.php?pid=2425 题意:给出起点和终点坐标 问起点到终点的最短时间  其中通过不同的路花费的时间不一样 路分四种  "T" 树 "."沙子 "#"路 "@"石头 石头是禁止通行的  树、沙子、路都可以走 只是时间不同   用bfs+优先队列来做  每次从时间最短的地方走

MM__1997的博客 409

HDU 2425 Hiking Trip(BFS+优先队列)

Hiking Trip Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1347    Accepted Submission(s): 597 Problem Description Hiking in the m

KongWX 486

hdu 2425 Hiking Trip (bfs+优先队列)

Problem Description Hiking in the mountains is seldom an easy task for most people, as it is extremely easy to get lost during the trip. Recently Green has decided to go on a hiking trip. Unfortunate...

weixin_30345055的博客 131

hdu - 1242 Rescue && hdu - 2425 Hiking Trip (优先队列+bfs)

http://acm.hdu.edu.cn/showproblem.php?pid=1242 感觉题目没有表述清楚,angel的朋友应该不一定只有一个,那么正解就是a去搜索r,再用普通的bfs就能过了。 但是别人说要用优先队列来保证时间最优,我倒是没明白,步数最优跟时间最优不是等价的吗?就算士兵要花费额外时间,可是既然先到了目标点那时间不也一定是最小的? 当然用优先队列+ a去搜索r是最稳妥...

weixin_30823683的博客 113

工业级线段树:支持区间赋值、加减与最值的生产实践

线段树是高效处理区间操作的基础数据结构,其核心原理在于分治建模与懒标记优化。在实时风控、时序聚合、库存调控等高并发场景中,单一操作已无法满足业务需求,必须协同支持区间赋值、区间加减和区间最值三类原子操作。这不仅带来懒标记优先级调度、最值链式维护、动态开点内存控制等技术挑战,更要求工程实现兼顾正确性、低延迟与内存稳定性。本文聚焦真实系统中的‘三操作共存’线段树设计,覆盖标记契约、节点复用、冷区回收与并发安全等关键实践,为构建亚毫秒级响应的生产级区间计算引擎提供可落地的技术路径。

weixin_34043301的博客 220

HDU2425:Hiking Trip(简单bfs,优先队列实现)

题目: 传送门 题意很简单就不解释了,水题一道。 #include &lt;iostream&gt; #include &lt;string.h&gt; #include &lt;stdio.h&gt; #include &lt;algorithm&gt; typedef __int64 ll; #define inf 0x3f3f3f3f #include &lt;math...

weixin_33805992的博客 96

hdu2425Hiking Trip

Hiking Trip Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1159    Accepted Submission(s): 511 Problem Description Hiking in the m

Min_lala的专栏 1075

hdu 2425 Hiking Trip (dfs)

hdu 2425 Hiking Trip (dfs) 优先队列 priority_queue

jw72jw的专栏 798
上一篇: HDU 2832 Snail’s trouble(数学题)
下一篇: HDU 3866 Moonfang's Birthday(贪心)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值