PAT甲级 1003 Emergency (Dj最短路)

别再傻傻分不清了!STM32定时器里Prescaler和ClockDivision到底有啥区别? 本文深入解析STM32定时器中Prescaler和ClockDivision的区别与应用场景。Prescaler作为定时器的'心跳调节器',决定计数频率;而ClockDivision则是输入捕获的'抗噪滤镜',有效抑制高频噪声。通过实战案例和示波器实测数据,帮助开发者避免常见配置误区,提升嵌入式系统稳定性。 阅读详情

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

这题为什么不标记book[begin]想了好久。

原因就是这个最少的路径更新取决于前一个点 。到前一个点的最短路径有多少条,到这个点的最短路径就有多少条。

如果标记掉起点,则挨着起点的点无法更新路径条数(最少一条),会导致结果为零。

和dp有点类似,需要一层层往下更新,状态取决于前一个点。

代码:


#include<iostream>
using namespace std;
int n,m,beg,des;
int c1,c2,l;
int temp,mmin;
int e[502][503],book[502],dis[502];
int num[502],w[502],total[502];
const int INF=99999999;
int main(){
    cin>>n>>m>>beg>>des;
    for(int i=0;i<n;i++)
        cin>>w[i];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            e[i][j]=INF;

    for(int i=0;i<m;i++){
        cin>>c1>>c2>>l;
        e[c1][c2]=e[c2][c1]=l;
    }
    for(int i=0;i<n;i++)
        dis[i]=INF;
    dis[beg]=0;
    //book[beg]=1;
    num[beg]=1;
    total[beg]=w[beg];
    for(int i=0;i<n-1;i++){
        mmin=INF;
        for(int j=0;j<n;j++){
            if(book[j]==0&&dis[j]<mmin){
                temp=j;
                mmin=dis[j];
            }
        }                                                          
        book[temp]=1;

        for(int v=0;v<n;v++){
            if(e[temp][v]<INF){
                if(dis[v]>dis[temp]+e[temp][v]){
                    dis[v]=dis[temp]+e[temp][v];
                    num[v]=num[temp];
                    total[v]=total[temp]+w[v];
                }
                else if(dis[v]==dis[temp]+e[temp][v]){
                    num[v]+=num[temp];
                    if(total[temp]+w[v]>total[v])
                        total[v]=total[temp]+w[v];
                }
            }
        }
    }
    cout<<num[des]<<" "<<total[des]<<endl;
    return 0;
}

 

基于一维卷积神经网络对机械振动信号进行分类并加以预测 基于一维卷积神经网络对机械振动信号进行分类并加以预测 *使用一维卷积神经网络训练振动信号进行二分类 2020年7月16日,一学期没等到开学,然而又放假了。 总览优快云中大多数卷积神经网络都是对二维图片进行分类的,而图片也都是常见的猫狗分类,minst手写数字分类。一维卷积神经网络的使用非常少见,有也是IDMB情感分类,和鸢尾花分类的。 作者研究生就读于河北一所双飞,全国排名270多,哈哈哈,不吹不黑。 在网上翻来翻去找不到一篇可以利用的代码去研究我的机械故障诊断,后来在无奈下到某宝搜寻到一段代码,可以利用 阅读详情

相关推荐

Fluent VOF造波从入门到放弃?手把手教你用k-w SST模型搞定波浪模拟

本文详细介绍了使用Fluent VOF和k-w SST模型进行波浪模拟的实战技巧,从参数设置到结果优化,帮助用户避开常见误区。通过工业项目验证的配置方案,提升波浪模拟的准确性和计算效率,特别适合处理多相流和复杂湍流场景。

weixin_27102543的博客 422

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 the length of each road between any pair of cities ar

mxy1060957459的博客 634

用Scratch实现凯撒密码:图形化编程与古典密码学的趣味结合

字符编码与移位运算是计算机处理文本数据的基础原理之一,它通过将字母映射为数字实现信息转换。在密码学领域,凯撒密码作为最经典的替换密码,直观地展示了基于规则字符替换的加密思想,其核心价值在于通过简单算法揭示加密解密的基本框架。这种原理在编程教育中尤为重要,能够帮助初学者理解循环、变量和字符串处理等核心概念。结合Scratch图形化编程环境,学习者可以通过拖拽积木可视化构建加密算法,将抽象的移位操作转化为交互式游戏。本项目以凯撒密码为例,通过实时密钥调整和动态字母表映射,生动演示加密过程,并自然融入暴力破解和密

weixin_32428571的博客 310

PAT甲级题库 1003 Emergency (25 分)

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 the length of each road between any pai

weixin_42445051的博客 554

AMESim柱塞泵建模全指南:从HCD库搭建到联合仿真

液压系统仿真中,轴向柱塞泵的建模始终是难点与热点。柱塞泵结构紧凑、功率密度高,在工程机械与航空航天领域应用广泛,然而其运动学与流体细节深度耦合,给仿真带来不小挑战。AMESim平台中的HCD库提供了一种从物理结构出发的建模思路,将柱塞泵分解为容积腔、节流口与机械约束等基础单元,从而真实刻画柱塞腔压力波动、配流特性和容积效率等关键行为,摆脱黑盒模型的局限。基于机理建模的仿真结果,可用于泵参数优化、故障特征分析以及控制策略验证。进一步结合AMESim与Simulink联合仿真,可以高效开发变量泵排量控制系统,研

weixin_29159441的博客 289

CDO批量处理nc文件:5分钟搞定CMIP6数据双线性插值(附完整代码)

本文详细介绍了如何使用CDO工具链中的`remapbil`命令,快速实现CMIP6数据的批量双线性插值处理。通过环境配置、核心操作步骤、高级优化技巧及典型报错解决方案,帮助科研人员高效处理大规模nc文件,显著提升气象数据处理效率。

weixin_29267307的博客 292

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 the length of each road between any pair of cities are mar

博客简介 482

神州路由器DHCPv6配置

神州路由器DHCPv6配置.。

weixin_41687096的博客 461

PAT真题练习(甲级)——1003 Emergency

PTA真题练习(甲级)——1003 最短路径问题

m0_61635175的博客 636

高匿反爬实战:Python打造无痕爬虫,规避风控系统追踪

网络层匿踪:核心是使用住宅IP代理池,按真实用户IP画像匹配,控制请求频率;协议层匿踪:动态生成请求头(每次都不同),参数添加随机噪声,避免规律化;行为层匿踪:模拟人类的非规律行为(贝塞尔轨迹、随机停顿、非精准点击);设备层匿踪:伪造Canvas/WebGL指纹,禁用webdriver标识,每次请求更换指纹;核心原则:无痕爬虫的本质是“无限接近真实用户”,所有维度都要消除爬虫特征,而非单一维度伪装。打造真正的无痕爬虫需要全维度的匿踪策略,单一维度的伪装极易被高级风控系统识别。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 2642

Python FastAPI 面试题及参考答案

FastAPI 的路由机制是其核心功能之一,用于将不同的 URL 路径映射到相应的处理函数。通过定义路由,可以构建出功能丰富的 API。在 FastAPI 中,使用装饰器来定义路由。在这个示例中,是一个装饰器,它将根路径"/"的 GET 请求映射到read_root函数。当客户端发送一个 GET 请求到根路径时,FastAPI 会调用read_root函数并返回结果。

大模型大数据攻城狮的专栏 2248

PTA 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 the length of each road between any pair of cities are ma

HaddockCaptain的博客 839

18、偏微分方程数值计算:粘性不可压缩流与电磁学的有限元方法

本文系统介绍了偏微分方程数值计算在粘性不可压缩流与电磁学中的应用,重点探讨了稳态与非稳态Navier-Stokes问题的混合有限元方法及求解技术,包括弱形式构建、半离散与时间离散格式、牛顿迭代法等。同时,详细阐述了电磁学中Maxwell方程的有限元与时域有限差分法(FDTD)求解方法,涵盖时间谐波与时域波方程、边界条件处理、稳定性分析与误差估计。结合MATLAB代码示例和实际案例,展示了速度场、压力、电场与磁场的数值模拟过程,并通过流程图与表格对比了两类问题的方法原理、应用场景与收敛性特性。最后展望了多物理

lemon的博客 88

PAT甲级1003 Emergency (25分)

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

weixin_43795683的博客 221

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

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

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

[PAT甲级]1003 Emergency

求最短路径的问题,用dj算法来解决,注意添加了条件,当路径长度相等时,优先选择救援队较多的路径;其次,要算出最短路径的条数,可以设置num_t[100]数组,记录从开始结点到当前结点 i 的最短路径的条数,而后面的相邻结点 j 若可以通过 i 以最短路径长度到达则 += num_s[i]即可,每次获得一个newP即是知道它的所有最短路径,找出所有能直连它的已经加入到newP过的即可。 As a...

T2777的博客 169

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

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

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

PAT甲级-1003 Emergency (25)(25 分)-图之最短路径

1003 Emergency (25)(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 resc...

kakazai.cn 2908

[PAT A1003]Emergency

[PAT A1003]Emergency 题目描述 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 ...

欢迎来到我的编程小屋 641

甲级PAT1003 Emergency(解坑)

1003Emergency (25)(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 t...

Joyceyang_999的博客 1285

最短路_1003 Emergency (25 分)

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...

A_Bo的博客 246

【再认真理解】1003. Emergency (25) Dijastra最优路径算法修改版求解

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

点点滴滴 3170

PTA练习题 1003 Emergency (25分) 【dfs最短路】

传送门:1003 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 r...

Waiting For You 334

PAT1003

1003. Emergency (25)时间限制 400 ms内存限制 65536 kB代码长度限制 16000 B判题程序 Standard 作者 CHEN, YueAs an emergency rescue team leader of a city, you are given a special map of your country. The ma...

哇塞 335

【PAT】Emergency(最短路条数-SPFA)

【PAT】Emergency(最短路条数-SPFA) 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 res

ACMer' 2239

PAT (Advanced Level) Practice 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...

菱形继承 496

PAT1003 Emergency (最短路)

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 ...

Low Coder的博客 280

PAT甲级 1003.Emergency(25) 题目翻译与答案

003.突发事件(25) 作为一个城市紧急援救队的指挥者,你得到了一个国家的特殊地图。地图上分散着几座城市,城市间用道路连接着。每个城市援救队的数量以及两座城市之间每条道路的长度已经在地图上标出。当某些城市发生了突发事件,需要你的帮助时,你的工作是带领你的队伍尽快的赶到事发现场,与此同时,召集尽可能多的在路上的队伍。 输入 每个输入文件包含一个测试实例。每个实例的第一行有四个正整数:N(<= 500)是城市的个数(城市的编号从0到N-1),M是道路的个数,C1和C2分别是你现在所在的城市以及你必须去救援

Coding home - 漂流瓶jz 5937
上一篇: HDU——1166 敌兵布阵(线段树点更新+区间查询)
下一篇: 一份基于链表的队列API实现【Java】
donCoder
博客等级 码龄9年 65粉丝 79原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值