杭电2680-Choose the best route(最短路反向建图)

CLion与STM32CubeMX联调:JLink GDB Server高效调试指南 本文详细介绍了如何搭建并配置CLion、STM32CubeMX与JLink GDB Server联调的现代化STM32开发环境。通过一站式环境搭建、工程创建、核心调试配置及高级技巧(如RTT日志),该组合实现了高效的代码编辑、可视化配置与稳定调试,大幅提升嵌入式开发效率与体验。 阅读详情

Choose the best route

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10891    Accepted Submission(s): 3529


Problem Description
One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend’s home as soon as possible . Now give you a map of the city’s traffic route, and the stations which are near Kiki’s home so that she can take. You may suppose Kiki can change the bus at any station. Please find out the least time Kiki needs to spend. To make it easy, if the city have n bus stations ,the stations will been expressed as an integer 1,2,3…n.
 

Input
There are several test cases.
Each case begins with three integers n, m and s,(n<1000,m<20000,1=<s<=n) n stands for the number of bus stations in this city and m stands for the number of directed ways between bus stations .(Maybe there are several ways between two bus stations .) s stands for the bus station that near Kiki’s friend’s home.
Then follow m lines ,each line contains three integers p , q , t (0<t<=1000). means from station p to station q there is a way and it will costs t minutes .
Then a line with an integer w(0<w<n), means the number of stations Kiki can take at the beginning. Then follows w integers stands for these stations.
 

Output
The output contains one line for each data set : the least time Kiki needs to spend ,if it’s impossible to find such a route ,just output “-1”.
 

Sample Input
5 8 5 1 2 2 1 5 3 1 3 4 2 4 7 2 5 6 2 3 5 3 5 1 4 5 1 2 2 3 4 3 4 1 2 3 1 3 4 2 3 2 1 1
 

Sample Output
1 -1
 

这个题用spfa没法判断重边,用floyd会超时,所以只能用dijkstra了,但是,记得要反向建图,因为只有一个终点,多个起点,所以反向建图只需要用一次dijlstra



#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int map[1010][1010],dis[1010],vis[1010];
int m,n,e,s[1010];
void dijkstra()
{
	int i,j,mi,mark;
	memset(vis,0,sizeof(vis));
	for(i=1;i<=m;i++)
		dis[i]=map[e][i];
	vis[e]=1;
	dis[e]=0;
	for(i=0;i<m;i++)
	{
		mi=INF,mark=-1;
		for(j=1;j<=m;j++)
		{
			if(mi>dis[j]&&!vis[j])
			{
				mi=dis[j];
				mark=j;
			}
		}
		if(mark==-1)
		break;
		vis[mark]=1;
		for(j=1;j<=m;j++)
		{
			if(!vis[j]&&dis[j]>dis[mark]+map[mark][j])
			dis[j]=dis[mark]+map[mark][j];
		}
	}
}
int main()
{
	int i,w,a,b,c;
	while(scanf("%d%d%d",&m,&n,&e)!=EOF)
	{
		memset(map,INF,sizeof(map));
		for(i=0;i<n;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			if(map[b][a]>c)
			map[b][a]=c;
		}
		dijkstra();
		scanf("%d",&w);
		int best=INF;
		for(i=0;i<w;i++)
		{
			scanf("%d",&a);
			best=best>dis[a]?dis[a]:best;
		}
		if(best==INF)
		printf("-1\n");
		else
		printf("%d\n",best);
	}
	return 0;
}



下面floyd代码虽然优化了,但是还是超时



#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int map[1010][1010],dis[1010],vis[1010];
int m,n,e,s[1010];
void floyd()
{
	int i,j,k;
	for(i=1;i<=m;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(map[i][j]==INF)
			continue;
			for(k=1;k<=m;k++)
			{
				if(map[j][k]>map[j][i]+map[i][k])
				map[j][k]=map[j][i]+map[i][k];
			}
		}
	}
	
}
int main()
{
	int i,w,a,b,c;
	while(scanf("%d%d%d",&m,&n,&e)!=EOF)
	{
		memset(map,INF,sizeof(map));
		for(i=0;i<n;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			if(map[b][a]>c)
			map[b][a]=c;
		}
		floyd();
		scanf("%d",&w);
		int best=INF;
		for(i=0;i<w;i++)
		{
			scanf("%d",&a);
			best=best>map[e][a]?map[e][a]:best;
		}
		if(best==INF)
		printf("-1\n");
		else
		printf("%d\n",best);
	}
	return 0;
}



3D视觉实战之双目相机物体尺寸实时测量 视差图滤波能够将稀疏视差转变为稠密视差,并在一定程度上降低视差图噪声,改善视差图的视觉效果,但是比较依赖初始视差图的质量。的目标是获得左右两个相机的内参、外参和畸变系数,其中内参包括左右相机的fx,fy,cx,cy,外参包括左相机相对于右相机的旋转矩阵和平移向量,畸变系数包括径向畸变系数(k1, k2,k3)和切向畸变系数(p1,p2)以及其他一些畸变类型。:相比于昂贵的专业设备,便宜的双目摄像头可以显著降低成本,使得实时点云生成技术更加普及和经济实惠。 阅读详情

相关推荐

Deepseek+Word插件:一键搞定论文翻译与润色的学术写作新革命

本文介绍了Deepseek Word插件如何革新学术写作流程,实现论文翻译与润色的一键操作。该插件深度集成于Word环境,能智能完成中英互译、语法修正、术语统一及逻辑优化,显著提升写作效率与文本质量,是研究者的高效AI助手。

weixin_29252171的博客 511

Choose the best route (最短路径,多起点)

One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend’s home as soon as possible . Now give you a map of the city’s traffic route, and t...

weixin_44584292的博客 777

TCNOpen实现TRDP通信协议(源码编译运行测试)

概述 本文介绍了通过TCNOpen开源源码实现TRDP通信,包括源码下载,开发环境搭建,编译运行,测试。 Linux环境下编译运行TRDP (一) 下载CANOpen源码。 下载地址:https://sourceforge.net/p/tcnopen/trdp/HEAD/tree/ (二) 源码编译 下载源码解压过后,在根目录文件readme-makefile.txt有介绍源码的配置和编译方法。 在trdp/config目录下可以看到包含在linux环境下的编译配置文件LINUX_config;执行”m

fengweibo112的博客 9631

Choose the best route

Problem Description One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend’s home as soon as possible . Now give you a map of the city

吃葡萄不吐葡萄皮 1220

用Verilog手把手教你搭建一个5级流水线的MIPS CPU(附完整代码与仿真)

本文详细介绍了如何使用Verilog从零构建一个5级流水线的MIPS处理器,包括开发环境配置、核心模块实现、流水线冲突处理等关键技术。通过完整的代码示例和仿真方法,帮助读者掌握CPU设计的基本原理和实践技巧,特别适合想要入门处理器设计的工程师和学习者。

weixin_30613727的博客 461

保姆级避坑指南:在Ubuntu 22.04上用ROS2 Humble搞定TurtleBot3的SLAM与导航(附5个常见报错解决方案)

本文提供了一份详细的Ubuntu 22.04上使用ROS2 Humble和TurtleBot3进行SLAM建图与导航的避坑指南,涵盖Gazebo启动失败、场景加载问题、环境变量设置、GLIBCXX版本冲突及Nav2参数配置等5个常见报错的解决方案,帮助开发者高效完成机器人导航项目。

weixin_29062823的博客 285

杭电2680——Choose the best route(Dijkstra)

Choose the best route(选择最佳路线) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2680 Problem Description One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend’s home as soon as possible . Now give

abcdefghikk的博客 469

通过薄膜太阳能电池中的热激电流量化陷阱状态

发光(led)和光伏(PV)器件的性能取决于光活性半导体材料的质量。由于材料杂质或在制造过程中在半导体材料中无意地引入缺陷,导致偏离最佳性能。这些缺陷被称为阱态,或简称“阱”,它是半导体带隙内的高能态。一般来说,陷阱的发生可能是由于材料杂质(在散装)或在不同材料层之间的界面。在有机半导体中,由于天然物质的无序性,阱态经常出现。在无机和杂化半导体(例如:杂化钙钛矿、硅……)中,晶界的存在是圈闭态的已知来源。由于陷阱产生的原因多种多样,它们对装置的影响也是多种多样的。由于载流子的多次捕获和释放事件,特别是浅阱的

FluximAG的博客 2849

Choose the best route 【最短路】+【反向建图】

One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend’s home as soon as possible . Now give you a map of the city’s traffic route, and th

lzs_lazy 422

NLP自然语言处理:神经网络语言模型(NNLM)

目录 一、传统语言模型 1.1 稀疏性 1.2泛化能力差 二、神经网络语言模型 2.1 前馈神经网络模型(FFLM) 2.2 循环神经网络模型(RNNLM) 2.2.1循环神经网络模型示例 2.2.2RNN语言模型训练过程 2.2.3RNN语言模型反向传播 2.2.4语言模型评估 语言模型的构建目的是为了对语言中的各要素的分布进行估计,具有较长的研究历史和广泛...

陈宸的博客 1万+

基于 FastAPI + LangGraph + LLM 大语言模型的通用 Agent 多智能体系统架构设计与开发实战、产业应用

FastAPI是一个现代、快速(高性能)的Python Web框架,专门用于构建API。它由Sebastián Ramírez(@tiangolo)创建,基于Starlette(用于Web部分)和Pydantic(用于数据部分)构建。性能优先:FastAPI是当前最快的Python Web框架之一,性能与NodeJS和Go相当。这得益于其基于Starlette的异步架构,能够充分利用Python 3.6+的async/await特性。开发效率。

AI天才研究院 230

杭电oj2680--Choose the best route(Dijkstra + 反向建图)

Choose the best route Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10601Accepted Submission(s): 3415 Problem Description One day ...

dixi7825的博客 181

基于 Simulink 的三相四线制整流器在三相不平衡负载下的中点电位平衡控制实战教程

本文为三相四线制整流器在中点电位不平衡时的Simulink仿真教程。首先分析中点电位漂移的电荷不平衡机理,提出零序电压注入控制策略。详细演示建模步骤:搭建三相四线制主电路,构建中点平衡控制算法(含MATLAB函数代码),实现控制信号叠加与PWM生成。通过对比仿真验证控制效果,并给出零序电压限幅、中性线电感影响等工程建议。该方案能有效抑制三相不平衡负载下的中点电位波动,保证系统稳定运行。

xiaoheshang_123的博客 50

HDU 2680Choose the best route (SPFA)

转载请注明出处:http://blog.youkuaiyun.com/u012860063 百度之星编程大赛——您报名了吗?  杭电ACM 2014暑期集训队——选拔安排~ Choose the best route Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/327

1405

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

【2680】Choose the best route

2680 dijkstra算法,参考了网上创建一个虚拟0结点的做法,规避了多个起点带来的困难,也优化了以终点作为起点然后再翻转的方法。只需要这样算一次就好了。 #include<bits/stdc++.h> using namespace std; const int MAX=0xfffffff; int mep[1010][1010]; int vis[1010],dis[1010]; int main(){ int n,m,s; int p,q,t; int w,start; whi

weixin_49646622的博客 127

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

[24] Choose the best route

dijkstra(hduoj)

syj2347的博客 469

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Choose the best route(Dijkstra)

Choose the best route(Dijkstra) 原题:hdu2680 这是一道有点难度的最短路径题,要想到以最后终点为起点进行搜索,或者新建一个起点用0表示,题目给的起点与0点连接且距离为零,其他点不与0点相连接,进行搜索。我一开始用Floyd来解,发现后来怎么优化都超时,看来这种单源点题目还是要用Dijkstra来解。 代码如下: #include &lt;iostream&gt...

qq_34851605的博客 307

14. Floyd + 朴素版Dijkstra

14. Floyd + 朴素版DijkstraFloyd(多源最短路径)(O(n^3))练习A - 最短路 HDU - 2544 (模板)F - Cow Contest POJ - 3660 (微变形)C - 一个人的旅行 HDU - 2066 (Floyd+剪枝)Dijkstra算法朴素版 (单源最短路径)(O(n^2))练习I - Til the Cows Come Home POJ - 2387 (模板)D - Choose the best route HDU - 2680 (记录一个奇奇怪怪的wa

qq_52008247的博客 544

Choose the best route ( dijkstra 路径翻转 )

Choose the best route One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend’s home as soon as possible . Now give you a map of the city’s traffic route, and the stations which are near Kiki’s

是微风,是晚霞,是无可替代 328

Choose the best route (最短路)

One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend’s home as soon as possible . Now give you a map of the city’s traffic route, and t

月殇 788

HDU 2680 Choose the best route

Problem Description One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend’s home as soon as possible . Now give you a map of the city

水人之路 561

Choose the best route HDU 各种优化加错误解析

Choose the best route         题目不难,就是如果看到题目的时候就能想到反向建图的话。那该题就相当于一道水题。但是这道题可以延伸出很多的内容,所以个人感觉有必要写一篇博客纪念一下。        根据题目的要求知道,如果按常规的思路的话,数据太大会超时。所以我们想到了因为终点就一个,所以我们反向建图,把终点当起点。然后本题是有重边的,一开始我是用邻接表写的所以被我

YouthDance 1092

hdu Choose the best route(最短路 --- Dijkstra)

Choose the best route Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4040    Accepted Submission(s): 1260 Problem Description One

勿忘初衷 2494
上一篇: 杭电2112-HDU Today(最短路)
下一篇: 杭电2066-一个人的旅行(最短路径)
Eric_keke
博客等级 码龄12年 37粉丝 221原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值