PAT (Advanced Level) Practise 1111. Online Map (30) Dijstra单源最短路

电机控制基础,小白入门篇 电机,这个藏在风扇、电动车、机器人里的“动力心脏”,如何精准控制它的转速、方向甚至力量?这篇博客专为完全零基础的小白打造,用“说人话”的方式拆解电机控制的底层逻辑,帮你从“看不懂电路图”到“能调个简单电机”。 电机控制不是“大神专属”,只要掌握“电生磁、磁生力”的底层逻辑,加上动手实践,小白也能快速入门。这篇博客会陪你从“看电机转”到“让电机听话”,把复杂的控制原理变成能上手玩的“小实验”。准备好你的面包板和电机,我们一起开启“电控之旅”吧! 阅读详情

1111. Online Map (30)

时间限制
300 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is guaranteed that a path exists for any request.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers N (2 <= N <= 500), and M, being the total number of streets intersections on a map, and the number of streets, respectively. Then M lines follow, each describes a street in the format:

V1 V2 one-way length time

where V1 and V2 are the indices (from 0 to N-1) of the two ends of the street; one-way is 1 if the street is one-way from V1 to V2, or 0 if not;length is the length of the street; and time is the time taken to pass the street.

Finally a pair of source and destination is given.

Output Specification:

For each case, first print the shortest path from the source to the destination with distance D in the format:

Distance = D: source -> v1 -> ... -> destination

Then in the next line print the fastest path with total time T:

Time = T: source -> w1 -> ... -> destination

In case the shortest path is not unique, output the fastest one among the shortest paths, which is guaranteed to be unique. In case the fastest path is not unique, output the one that passes through the fewest intersections, which is guaranteed to be unique.

In case the shortest and the fastest paths are identical, print them in one line in the format:

Distance = D; Time = T: source -> u1 -> ... -> destination

Sample Input 1:
10 15
0 1 0 1 1
8 0 0 1 1
4 8 1 1 1
3 4 0 3 2
3 9 1 4 1
0 6 0 1 1
7 5 1 2 1
8 5 1 2 1
2 3 0 2 2
2 1 1 1 1
1 3 0 3 1
1 4 0 1 1
9 7 1 3 1
5 1 0 5 2
6 5 1 1 2
3 5
Sample Output 1:
Distance = 6: 3 -> 4 -> 8 -> 5
Time = 3: 3 -> 1 -> 5
Sample Input 2:
7 9
0 4 1 1 1
1 6 1 1 3
2 6 1 1 1
2 5 1 2 2
3 0 0 1 1
3 1 1 1 3
3 2 1 1 2
4 5 0 2 2
6 5 1 1 2
3 5
Sample Output 2:
Distance = 3; Time = 4: 3 -> 2 -> 5


#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int maxn = 500 + 10, INF = 0x3f3f3f3f;
int N, M, s, e;
int dis[maxn][maxn], tim[maxn][maxn], cnt[maxn][maxn];
int pd[maxn], pt[maxn], dd[maxn], dt[maxn];
bool vis[maxn];

//dijstra(dis, tim, dd, pd);
//dijstra(tim, cnt, dt, pt);
void dijstra(int map1[][maxn], int map2[][maxn], int *d1, int *p) {
	int d2[maxn];
	for (int i = 0; i < N; i++) {
		d1[i] = INF;
		d2[i] = INF;
	}
	memset(vis, false, sizeof(vis));
	for (int i = 0; i < N; i++) {
		d1[i] = map1[s][i];
		d2[i] = map2[s][i];
	}
	d1[s] = 0;
	p[s] = s;
	vis[s] = true;
	for (int t = 1; t <= N - 1; t++) {
		int MIN = INF, min;
		for (int i = 0; i < N; i++) {
			if (!vis[i]) {
				if (d1[i] < MIN) {
					min = i;
					MIN = d1[i];
				}
			}
		}
		vis[min] = true; //不要忘记标记
		for (int i = 0; i < N; i++) {
			if (!vis[i]) {
				if (d1[min] + map1[min][i] < d1[i]) {
					d1[i] = d1[min] + map1[min][i];
					d2[i] = d2[min] + map2[min][i];
					p[i] = min;
				}
				else if (d1[min] + map1[min][i] == d1[i] && d2[min] + map2[min][i] < d2[i]) {
					d2[i] = d2[min] + map2[min][i];
					p[i] = min;
				}
			}
		}
	}
}

void output(int *a) {
	int out[maxn], len = 0;
	int j = e;
	while (j != s) {
		out[len++] = j;
		j = a[j];
	}
	out[len++] = j;
	for (int i = len - 1; i >= 0; i--) {
		if (i != 0) {
			printf("%d -> ", out[i]);
		}
		else {
			printf("%d\n", out[i]);
		}
	}
}

int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i != j)
				dis[i][j] = tim[i][j] = INF;
			else
				dis[i][j] = tim[i][j] = 0;
		}
	}
	for (int t = 0; t < M; t++) {
		int v1, v2, one, len, time;
		scanf("%d%d%d%d%d", &v1, &v2, &one, &len, &time);
		dis[v1][v2] = len;
		tim[v1][v2] = time;
		if (!one) {
			dis[v2][v1] = len;
			tim[v2][v1] = time;
		}
	}
	scanf("%d%d", &s, &e);

	for (int i = 0; i < N; i++) {
		pd[i] = s;
	}
	dijstra(dis, tim, dd, pd);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cnt[i][j] = 1;
		}
	}

	for (int i = 0; i < N; i++) {
		pt[i] = s;
	}
	dijstra(tim, cnt, dt, pt);
	bool flag = true;
	for (int i = 0; i < N; i++) {
		if (pd[i] != pt[i]) {
			flag = false;
			break;
		}
	}
	if (flag) {
		printf("Distance = %d; Time = %d: ", dd[e], dt[e]);
		output(pd);
	}
	else {
		printf("Distance = %d: ", dd[e]);
		output(pd);
		printf("Time = %d: ", dt[e]);
		output(pt);
	}
	return 0;
}




【DaVinci Developer工具实战】01 - DaVinci Developer的主要功能介绍 显示 ECU composition’s【复合组件】 端口的数据元素到 ECU 网络信号的映射,一般我们采用自动映射进行CAN DBC文件中的网络信号到软件组件端口中的数据元素【DataElement】的映射。你可以把它看成Matlab中的各种工具库,我们可以直接通过它来构造我们的原型/设计原型,也可以理解成C++中的类,我们实例化的过程就是构型原型的过程。蓝图就是模板的意思,我们可以根据蓝图直接生成蓝图的原型,也叫做模板的实例化。显示 ECU 项目的所有端到端受保护数据元素的概览。显示选定对象的属性。.. 阅读详情

相关推荐

超越音频!STM32 SAI接口在AD7768高速ADC采集中的妙用(含PCB布局指南)

本文深入探讨了如何将STM32的SAI接口应用于AD7768高速ADC的数据采集系统,超越了其传统的音频应用范畴。文章详细解析了SAI协议与ADC时序的匹配方法,提供了从CubeMX配置、DMA数据搬运到关键PCB布局指南的完整实战方案,旨在帮助工程师实现稳定、高精度的工业级高速数据采集。

efc12345678的博客 320

PAT (Advanced Level) Practise 1111 Online Map (30)

1111. Online Map (30) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Input our current position and a destination, a

Occult 1139

CISSP背书三次失败后的终极解决方案

本文分享了作者CISSP认证三次线上背书审核失败的经历与终极解决方案。针对(ISC)²官方审核的严格性,文章详细剖析了使用公积金证明、工作证明盖章签字等常见材料的误区,并最终提出了通过构建“官方邮件往来”证据链的核心策略,以动态、可验证的方式成功通过审核,为后来者提供了详实的避坑指南和实操清单。

weixin_29219539的博客 167

PAT甲级 1111. Online Map (30)

Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is g...

moffy_abo的博客 1383

瑞萨单片机-硬件I2C从设备

瑞萨单片机上实现I2C从机,根据主机发来的数据,从机返回或者保存数据2、R5F1115AxFL最多支持3个从设备地址(即可以作为三个从设备)3、从接收模式:直接将数据保存到RAM中,接收完再处理4、从发送模式:按照I2C读取传感器数据经验,主机读取从设备时,从设备需要立刻返回数据的,但是程序要如何实现一收到指令就返回特定的数据?(时钟拉伸)这里先跳过,我们先实现返回固定的数据。

qq_27893147的博客 3228

手把手教你搞定倍福TwinCAT3 4020 Full版安装(含VS配置与Win10系统避坑指南)

本文详细介绍了倍福TwinCAT3 4020 Full版的安装流程,包括Visual Studio配置和Windows 10系统下的常见问题解决方案。从环境预检、主程序安装到帮助文档与补丁安装技巧,提供全面的避坑指南,帮助用户顺利完成TwinCAT3的安装与配置。

weixin_26897585的博客 534

solution Of Pat 1111. Online Map (30)

1111. Online Map (30)Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is

风先生的日常专栏 2403

使用GBIF获取生物多样性数据与GIS的结合

随着全球生物多样性的重要性日益凸显,越来越多的研究人员和保护机构开始利用地理信息系统(GIS)来分析和可视化生物多样性数据。GBIF(全球生物多样性信息设施)作为一个全球性的生物多样性数据库,提供了大量的物种分布和分类信息,为研究人员和保护工作者提供了宝贵的数据资源。本文将介绍如何使用GBIF API获取生物多样性数据,并将其与GIS技术相结合,以便更好地理解和研究生物多样性。利用GIS的强大功能,我们可以在地理空间上可视化物种分布、分析物种多样性的空间格局,并为保护生物多样性提供科学依据。

BnxBackend的博客 1776

1111. Online Map (30)-PAT甲级真题(Dijkstra + DFS)

1111. Online Map (30)Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is...

柳婼 の blog 5535

海康DS-7604N-K1/RTB固件包

【摘要】海康DS-7604N-K1/RTB萤石云设备发布V4.30.091版本升级程序(2022.09.19),仅适用于指定型号。升级前需先升级至V3.4.106基础版本,刷机会重置设备为未激活状态,需重新设置admin密码。该机型支持密码/手势登录,无密码时可通过U盘升级。注意事项:升级存在风险,需确认程序适用性;升级过程严禁断电;必须阅读压缩包内的刷机说明。此为定制机型,非必要不建议升级。(150字)

海康威视技术支持 1614

AgentScope 实战训练营-构建元规划智能体(Meta Planner Agent)—— 从 0 到 1 完整实现

本文介绍了基于AgentScope框架开发的元规划智能体(Meta Planner Agent)系统。该系统通过任务拆解和子代理编排机制,实现复杂任务的自动化处理。核心架构分为用户层、规划器层和子代理层,其中规划器作为"项目经理"负责任务分解、创建子代理并协调执行流程。关键技术包括AgentScope多智能体框架、DashScope大语言模型、PlanNotebook计划管理工具等。

program哲学 379

PAT_A、1111. Online Map (30)

1111. Online Map (30)Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is

longtails的博客 1070

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

pat1111 Online Map

题意:输入一个图,边权包括路径长度,要消耗的时间。输出最短路径,多条则输出耗时最短的,输出耗时最多的路径,多条则输出经过点最少的。 思路:spfa跑两下就好。 代码 #include &lt;iostream&gt; #include &lt;cstdio&gt; #include &lt;algorithm&gt; #include &lt;cmath&gt; #include &lt;...

cccsssxxx 994

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

PAT甲级 1111 Online Map(最短路径的应用)

题目链接:点击打开链接思路:写的比较繁琐,利用dijkstra算法分别去求最短路径和最快路径,再按照要求输出即可。还写了一个搜索的版本,由于剪枝函数不够优化,复杂度过高,最后一个测试点超时,27分。#include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;iostream&gt; #include &lt;vector&gt; #i...

不忘初心 2060

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

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

PAT甲1111 Online Map(30 分)

#include &lt;string.h&gt; #include &lt;stdio.h&gt; #include &lt;vector&gt; #include &lt;queue&gt; #include &lt;algorithm&gt; #include &lt;map&gt; #include &lt;string&gt; #include &lt;iostream&

一点点 421

1111. Online Map (30) 最短路径、DFS

时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two p

一叶知秋 629

PAT甲级1111 Online Map

写这个题解并没有太大意义。。只是给需要用到的同学写的。 题意比较直: 给予一个地图,N个点M条路,每条路有对应的时间和长度。最后给出终点和起点,求长度最短(如果存在多条长度最短的路线,求用时最少那条,保证此答案唯一)的路线和时间最短(如果存在多条时间最短的路线,求通过点最少的那条,保证此答案唯一)的路线。保证终点和起点之间至少存在一条路径。 那么就没啥好说的了,一个广搜就可以解决,不过题目要

Vis_Stu的专栏 743

PAT(A)1111 Online Map (30)(最短路)

题目大意: 给你n个点,m条路。 接下来m行,V1 V2 one-way length time one-way 表示是不是单向边,1是0否 求最短和最快的距离和时间 并输出路径。 如果路径不一样,则按一下格式输出 Distance = D: source -> v1 -> … -> destination Time = T: source -> w1 ->

No Program No Life 774

PAT Advanced 1111. Online Map (30)

问题描述:1111. Online Map (30)时间限制300 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueInput our current position and a destination, an online map can recommend several paths. Now your job is to recommen...

kircher的博客 291

1111 Online Map(30 分)

Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is g...

ysq96的博客 869

1111. Online Map (30)

1111

ZhangVeni的博客 846

PAT甲级1111 【Online Map】 (30)

补充:2018.8.25更新,写这种题一定要静心,否则小bug会不经意间不断出现,再写一遍代码行居然和上次一样,不过方法略有差别。 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;vector&gt; #include&lt;cstring&gt; using namespace std; const int maxn ...

gq__97的博客 369

PAT-A1111. 图-Dijkstra输出最短路径

Dijkstra查找单源最短路径,DFS输出路径

lilysara的博客 703

PAT甲级1111 Online Map (30 分)【Dijkstra+dfs】

Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is g...

Imagirl1的博客 476

(PAT)1111. Online Map(迪杰斯特拉算法)

不用模板徒手码代码真TM刺激。。PAT,我有句MMP不知当讲不当讲。 迪杰斯特拉,一个非常不错的算法,老迪也是个牛人,哎呀,跑题了。。不懂DJ算法的话,参考:迪杰斯特拉算法 1111. Online Map (30) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判

路漫漫 始于足下 1469

PAT(A) - 1111. Online Map (30)

Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is g

flx413的博客 407
上一篇: hdu4278 Faulty Odometer 八进制转十进制
下一篇: hdu4287 Intelligent IME STLmap散列查找
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址