PAT 1003. Emergency (25)

centos断电重启卡在登录前界面的问题解决 出现这个情况的原因猜测是断电,启动后就卡在登录前界面,只有网络是通的,其他服务貌似都没正常启动,ssh远程终端也连不上 ctrl+alt+1,切换到详细信息模式下看到这样的错误: 就是文件系统xfs有损坏 查资料都说是需要通过xfs_repair来修复,但这里进不了终端了,解决办法是进入”单用户模式”: 开机时进入如下界面: 按e键出现下面界面 按方向键下,定位到最后,找到“ro”一行,ro的意思是readonly,将“ro”替换成 rw init=/sysroot/bin/sh,. 阅读详情

As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.

Input

Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) - the number of cities (and the cities are numbered from 0 to N-1), M - the number of roads, C1 and C2 - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c1, c2 and L, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C1 to C2.

Output

For each test case, print in one line two numbers: the number of different shortest paths between C1 and C2, and the maximum amount of rescue teams you can possibly gather.
All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.

Sample Input
5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1
Sample Output

2 4


题目分析: dfs操作实现即可。

代码:

#include<stdafx.h>

#include <iostream>
using namespace std;

int N, M, C1, C2;
int Rescue[505] = {0};
int L[505][505] ={0};

bool visited[505] = {false};
int currDis = 0;
int MinDis = 1<<30;
int NumRoad = 0;
int MaxRescue = 0;
int CurrRescue = 0;

void dfs(int curr)
{
	int i;
	if (curr == C2)
	{
		if (currDis < MinDis)
		{
			MinDis = currDis;
			MaxRescue = CurrRescue;
			NumRoad = 1;
		}
		else if(currDis == MinDis)
		{
			if (CurrRescue > MaxRescue)
			{
				MaxRescue = CurrRescue;
			}
			NumRoad++;
		}
		return;
	}

	for (i = 0;i<N;i++)
	{
		if ( i != curr && !visited[i] && L[i][curr])
		{
			currDis += L[i][curr];
			CurrRescue += Rescue[i];
			visited[i] = true;
			dfs(i);
			currDis -= L[i][curr];
			CurrRescue -= Rescue[i];
			visited[i] = false;
		}
	}
}
int main()
{
	scanf("%d %d %d %d", &N, &M, &C1, &C2);

	int i;
	for (i = 0;i<N;i++)
	{
		scanf("%d", &Rescue[i]);
	}

	//int j;
	int tmp1, tmp2, tmp3;
	for (i = 0;i<M;i++)
	{
		scanf("%d %d %d", &tmp1, &tmp2, &tmp3);
		L[tmp1][tmp2] = tmp3;
		L[tmp2][tmp1] = tmp3;
	}

	visited[C1] = true;
	//currDis += Rescue[C1];
	CurrRescue += Rescue[C1];
	dfs(C1);

	printf("%d %d", NumRoad, MaxRescue);
	return 0;
}


Altium Designer(AD24)导入DDB库文件(Protel 99SE)方法 Altium Designer和Protel均为Altium公司开发的软件。本文介绍Altium Designer 24软件导入DDB库文件(Protel 99SE)方法。 阅读详情

相关推荐

Diffix3D+复现

上下载模型,将其放在一个目录中,并将目录名填在demo代码中from_pretrained的cache_dir参数里。目录结构应该是"<PATH>/nvidia/difix/…给的requirements文件中pytorch和xformers的版本没有指定,这里测试过以下版本,可以成功运行。将readme中的demo代码新建一个python脚本复制进去,然后将脚本放在src目录中运行。如果遇到网络问题无法加载huggingface上的预训练模型,可以手动从。如果出现,以下错误重新。

NeverMakeIt的博客 1085

记一次XFS文件系统崩溃的处理

1、问题出现 当使用rpm安装服务时,出现如下问题,当使用yum时也是一样 查了/var/log/messages发现以下错误,看起来是XFS的问题 可以发现dm-0实际是bel-root的问题,查了网上很多解决方法都是说要使用xfs_repair去修复对应的磁盘,但是我这里是没有用的,会报xfs_repair: /dev/dm-0 contains a mounted filesystem ...

dhRainer的博客 8572

科研党必备:Python脚本批量下载DOI文献的保姆级教程(附避坑指南)

本文为科研人员提供了一份详细的Python脚本批量下载DOI文献的教程,涵盖环境配置、核心功能实现、性能优化及常见问题解决。通过自动化脚本,研究者可高效完成文献批量下载,显著提升科研工作效率,特别适合需要处理大量文献的研究团队使用。

weixin_26965807的博客 477

1003. Emergency (25)-PAT

1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emergency rescue team leader of a city, yo

兵临城下 1782

使用MID360在室内快速定位

在预构建的点云地图中实现实时3D全球定位。通过融合FAST-LIO的低频全局定位(约0.5~0.2Hz)和高频里程计,整个系统的计算效率很高。消除里程计的累计误差初始定位可以通过RVIZ的粗略手动估计或来自另一个传感器/算法的姿势来提供。

CTwinkle的博客 1162

中国30米逐年植被净初级生产力(NPP)数据集(1982年至今CASA模型)

1.3 气温、降水、地表太阳辐射数据 气温和降水数据月度空间插值数据是基于全国2400多个站点的日观测数据,在计算各气象要素月值的基础上,基于Anusplin软件插值生成的1982年以来各月度30米分辨率气温和降水栅格数据,插值过程中引入高程作为协变量。气温单位为℃,降水单位为mm。1.2 土地覆盖数据 土地覆盖数据来源于1985 年-2020年全球30米精细地表覆盖动态监测产品,该数据集包含29个地表覆盖类型,进行拼接、裁剪、重分类和重采样处理,获得8期250米分辨率的植被类型数据。

地球资源数据云的官方博客 2839

xfs文件系统修复-xfs_repair

公司虚拟平台中六台虚拟机,Centos操作系统,因为停电,坏了五台,无比郁闷,开发环境都在上面部署着。 如果全部重新安装费时费力。 安装的时候选择了xfs文件系统。 网上查询到xfs文件系统可以通过xfs_repair命令进行修复,就进行了尝试。 ...

天道 4万+

模拟CMOS集成电路设计入门学习(1)

模拟CMOS集成电路设计入门学习(1):二级效应

qq_61052827的博客 3086

centos8 启动失败

进入救援模式 http://www.7vo.cn/article/51.html https://blog.csdn.net/dhrainer/article/details/91453450 :在linux16这行的后面输入“rd.break console=tty0”然后按“ctrl+x“如下图 进入安全模式后,使用umount /dev/mapper/bel-root去卸载当前的卷,(这一步很重要),而后执行xfs_repair /dev/mapper/bel-ro...

sun007700的专栏 2516

107.在 Vue 3 中使用 OpenLayers 实现视图联动功能

是一个非常强大的 Web 地图渲染库,支持多种地图数据格式和交互操作。在 Vue 3 中,我们可以利用。绑定到真实的 DOM 元素上,我们就可以用它们来初始化 OpenLayers 地图。来封装和管理 OpenLayers 地图的状态,从而更高效地开发地图应用。,即两个地图窗口共享同一个视图(View),从而实现同步缩放、拖动等操作。这可以确保 Vue 组件销毁时,OpenLayers 也正确销毁地图实例。,并且它们会同步缩放和拖动,达到地图联动的效果。这样,无论你拖动哪个地图,另一个都会同步变化。

小彭的博客 1938

Claude Code Skills 入门:内置技能与自定义技能开发

│ Skill 的特点 │1. 封装性:把复杂操作封装成简单命令2. 可复用:一次定义,随处使用3. 可定制:支持参数传入4. 可发现:通过 /skill-name 方式调用打个比方,如果说 Claude Code 的基础工具是「原材料」,那 Skills 就是「预制菜」——只需要简单加热(调用),就能得到成品(结果)。你可以创建自己的 Skill 来封装常用操作。Skill 支持参数,通过。

gaoxiang_120的专栏 671

PAT甲级 - 1003 Emergency (25 分)

题目链接:(PAT甲级)1003 Emergency (25 分) As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of ...

247

华为OD机试 - 幸运数字(Java 2024 E卷 100分)

华为OD机试 2024E卷题库疯狂收录中,刷题。

学Java,找哪吒 3776

PAT(甲级)1003.Emergency(25)

PAT 1003.Emergency(25) As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams...

乐行僧的博客 334

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

PAT甲级1003 Emergency (25分)

PAT甲级1003 Emergency (25分) 题目: 解题思路:由于是第一次接触到图的问题,所以重温了一下数据结构的Dijkstra算法吧,不太会写,在搜集了各种资料之后终于AC,所以做了详细的注释,可能下次遇到Dijkstra会好受一点吧 附上AC代码: #include <cstdio> #include <cstring> #include <algori...

weixin_43795683的博客 221

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

[PAT-Advanced]A1003 Emergency (25)

理解和记忆Dijkstra算法

Duke 293

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

PAT 1003 Emergency(25)Python

题目描述1003. Emergency (25)As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams

日复一日,年复一年 949

Pat 1003 Emergency (25)

1003Emergency(25分) As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams...

YIU 189

PAT真题练习(甲级)1003 Emergency (25 分)

PAT真题练习(甲级)1003 Emergency (25 分) As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of re...

Be Quick & Clever & Lucky 328

PAT(甲级)1003 Emergency (25 分)

题目来源: PAT(甲级)1003 Emergency (25 分) 题目描述: Sample Input: 5 6 0 2 1 2 1 5 3 0 1 1 0 2 2 0 3 1 1 2 1 2 4 1 3 4 1 Sample Output: 2 4 题目翻译: 作为一个城市的紧急救援队队长,你会得到一张你所在国家的特别地图。这张地图显示了几个分散的城市,由一些道路连接起来。地图上标出了...

sinat_41835935的博客 249

PAT A1003 Emergency (25分)

PAT A1003 Emergency (25分) 题目 原题链接 题目大意 输入每个城市医疗队的数目,以及相连城市之间的距离,计算求出原城市到目的城市最短路径的路径数,以及最多能聚集医疗队的数目 大体思路 该题是一个典型的dijkstra+DFS的模板题目,掌握了该模板,就可以解决这一类典型问题。 代码 #include<stdio.h> #include<algorithm&...

qq_41706836的博客 181

【PAT甲级题解记录】1003 Emergency (25 分)

对于单源最短路径(这道题也应该不会出现负边),一般我们最常用的就是dijkstra算法,但这里不单单是求最短路径,但是依旧可以用这个算法,算是dijkstra求最短路径的变题。

retr0的博客 539

Day1: [PAT] 1003 Emergency (25 分)

Day1: [PAT] 1003 Emergency (25 分) 题源: 来自PAT甲级题库1003:https://pintia.cn/problem-sets/994805342720868352/problems/994805523835109376 思路: Dijkstra算法的“双优先级版”,首先要熟练Dij算法的基本型。本题的第一优先级是路径权值,第二优先级是救援队人数(点的权值呗...

qq2215459786的博客 155

PAT 甲级 1003 Emergency 25分

题目描述 As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and ...

qq_26073557的博客 314

PAT A1003 Emergency (25 分)

1003Emergency(25分) As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams...

树叶子的博客 291

PAT 1003 Emergency (25)

写了一段时间的HDU上的搜索,现在回来写这道PAT上的,顿时觉得PAT上的难度确实是要小一些的,但是这里暴露了自己的问题,以前都不怎么用宏定义,在这里心血来潮用了一次,一直报错但是一直没找到问题,这里要提醒自己,宏定义常量的时候后面不要加; #include #include #define MAX1 999 int start,ends,n,m,visit[505],map[505]

Whisker_yu的专栏 593
上一篇: PAT 1002. A+B for Polynomials (25)
下一篇: PAT 1004. Counting Leaves (30)
xuxumoi
博客等级 码龄16年 16粉丝 151原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值