[动态规划]Pku3377--Ferry Lanes

产业园区如何高效对接企业技术需求与高校科研成果?.docx 科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。 立即下载

http://acm.pku.edu.cn/JudgeOnline/problem?id=3377

 

Ferry Lanes
Time Limit: 2000MS Memory Limit: 131072K
Total Submissions: 2563 Accepted: 510

Description

Arthur lives in a small city which is partitioned into two districts, the northern and the southern, by a river flowing through. The northern and southern districts are connected by N + 1 bidirectional ferry lanes, numbered 0 to N from west to east. Each ferry lane connects two docks in separate sides of the river. No two lanes share the same dock or cross each other.

Today Arthur needs to deliver a package from one dock to another. He knows the sailing time of each ferry lane and the time cost by walking from one dock to an adjacent one along the river bank. Arthur wants to know what is the minimum time his delivery will cost.

 

 

Input

The input consists of several test cases. The first line of each consists an integer N ( 1 ≤ N ≤ 1,000,000). The second line consists of two pairs of integers describing the starting and finishing docks, where the first of each pair represents the district (0 means northern and 1 means southern) and the second represents the lane number. The third line contains N integers describing the time cost by walking between two adjacent docks on the northern bank from lane0 to laneN. The fourth line contains N + 1 integers describing the sailing time of each ferry lane. The last line contains N integers describing the time cost by walking between two adjacent docks on the southern bank from lane0 to laneN. N = 0 indicates the end of input.

Output

For each test cases output one line contains the minimum time. You may assume the answer fits in a signed 64-bit integer.

Sample Input

4
0 0 1 4
1 3 5 7
3 5 1 3 7
1 3 7 5
0

Sample Output

17

Source

 

题目大意:如题目的图中所示,南北岸各有n+1个船坞,编号为0~n,给出船坞之间的双向通路和水路(一个船坞对应一条水路,水路不交叉)所需时间,求从指点船坞到指点船坞最少耗时。

 

分析:可以用最短路解决,不过n有10^6之大,所以要用spfa之类的高效算法才行。不一定要构图,因为边是一定的。

我用的是O(n)的dp。

如果给出的起点坐标大于终点坐标,则交换。令f[i,0]f[i,1]分别表示走到北岸第i个点和南岸第i个点的最少时间,不难得到:

f[i,0]:=min(f[i-1,0]+cost,f[i-1,1]+cost+lane).

f[i,1]同理。

初始,要先求出从起点到对岸的最短路。只要向左扫描下就行了。

dp之后不能马上得到最小值,因为可以在对岸向右后渡河。求法和初值一样,向右扫描。

一个经典的模型。一开始在向右扫描时有疏漏,wa了几次...

 

 

codes:

 

 

国央企创新负责人如何快速掌握本地科技资源分布与匹配情况?.docx 科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。 立即下载

相关推荐

国央企创新负责人如何实现科技成果的精准识别与高效筛选?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

poj 3377 Ferry Lanes(dij+heap)

Ferry Lanes Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 4070   Accepted: 866 Description Arthur lives in a small city which is partitioned into two di

WEYuLi的专栏 1230

带隙基准源要点

要点: 负反馈>正反馈;电流镜匹配;双极型晶体管匹配;电阻匹配; 经过R0的电流????????????=????????????????−????????????????????????=∆????????????????????i_R0=(〖VBE〗_1-〖VBE〗_2)/R_0 =∆VBE/R_0 经过R1的电流????????????=i_R1= ????????????????????VBE/R_1 零温电流I = ∆????????????????????∆VBE/R_0 +

HI_WALLE的博客 2264

POJ 2336 动态规划(DP) Ferry Loading II

题目链接:http://poj.org/problem?id=2336 分析:设想我们要求的是第i辆车最早到达目的地的时间( dp[i] ),则我们只要找到在它之前的n辆车中能最早到达目的地的那辆(mi),则它的前一辆是(mi-1)最小时间为dp[mi-1](并返回),最后一次送mi~i辆车过去,时间会最短. 即:dp[i]=max(dp[mi-1],f[i])+t*2 ; #in

PWZER 1527

【YOLO 系列】基于YOLO V8的智能车载交通标志识别系统【python源码+Pyqt5界面+数据集+训练代码】

本文详细介绍了基于YOLO V8构建智能车载交通标志识别系统的完整流程。从环境搭建、数据集准备、模型训练到PyQt5图形界面开发,提供了Python源码和实战代码,帮助开发者快速实现高精度、实时的交通标志检测应用,提升驾驶辅助系统的开发效率。

wdx012345的博客 966

基于角谱传播的MATLAB仿真:从相位恢复看自由空间光传播

本文详细介绍了基于角谱传播理论的MATLAB仿真方法,用于模拟自由空间光传播过程。通过傅里叶光学原理,将光场分解为频谱并应用传播相位滤波器,实现了从纯相位物体到可观测衍射图样的仿真。文章结合具体代码,演示了如何利用角谱法进行相位恢复,为计算成像和生物医学检测等领域的研究提供了实用的仿真工具和思路。

weixin_29055699的博客 282

noi2004-郁闷的出纳员(cashier) 解题报告

  NOI2004郁闷的出纳员【问题描述】 OIER公司是一家大型专业化软件公司,有着数以万计的员工。作为一名出纳员,我的任务之一便是统计每位员工的工资。这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常调整员工的工资。如果他心情好,就可能把每位员工的工资加上一个相同的量。反之,如果心情不好,就可能把他们的工资扣除一个相同的量。我真不知道除了调工资他还做什么其它事情。

幻想の天地 2051

Three 之 three.js (webgl)绘制物体模型尺寸虚线包围框工具简单封装 DashLinesBoxTool

Three js 开发的一些知识整理,方便后期遇到类似的问题,能够及时查阅使用。本节介绍, three.js (webgl) 中绘制物体模型尺寸虚线包围框工具简单封装 DashLinesBoxTool,主要是给实物绘制线框,有点像AI 识别正方形包裹框的效果。其中,如果有不足之处,欢迎指出,或者你有更好的方法,欢迎留言。

仙魁XAN 2106

[动态规划]Pku2411--Mondriaan's Dream

Mondriaans DreamTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 3732 Accepted: 2156DescriptionSquares and rectangles fascinated the famous Dutch painter

幻想の天地 2022

ACS运动控制器编程语言

ACS运动控制器采用SPiiPlusLanguage(SPL)作为核心编程语言,该语言基于C语法设计,内置丰富的运动控制指令,支持点位运动、插补等复杂控制。控制器提供专用开发工具SPiiPlusManager和ACSStudio,支持图形化编程与调试。同时兼容TCP/IP、EtherCAT等多种扩展接口,便于与上位机或PLC集成。使用时需注意实时性优先级、轴参数匹配等关键事项。官方文档和示例程序为开发者提供了完善的学习资源。

StevenChen的博客 621

人工智能在软件测试中的广泛应用领域

人工智能在软件测试中的应用领域涵盖了自动化测试、缺陷预测和缺陷检测、智能化测试报告生成等方面。以上提供的示例代码只是其中的一小部分,实际上,人工智能在软件测试中还有许多其他的应用。通过结合人工智能和软件测试,可以提高测试效率和质量,减少测试工作的人力成本,并帮助开发人员更好地理解和改进软件产品。人工智能(Artificial Intelligence,简称AI)在软件测试领域的应用越来越广泛。下面将介绍几个人工智能在软件测试中的主要应用领域,并提供一些相关的源代码示例。

FycPerformance的博客 462

[动态规划+矩阵快速幂优化]Pku3420--Quad Tiling

Quad TilingTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1801 Accepted: 698DescriptionTired of the Tri Tiling game finally, Michael turns to a more

幻想の天地 1385

特征选择/筛选方法总结

作者:jliang https://blog.youkuaiyun.com/jliang3 1.特征选择介绍 1)特征分类 相关特征:对于学习任务(例如分类问题)有帮助,可以提升学习算法的效果; 无关特征:对于我们的算法没有任何帮助,不会给算法的效果带来任何提升; 冗余特征:不会对我们的算法带来新的信息,或者这种特征的信息可以由其他的特征推断出; 2)特征选择的目的 对于一个特定的学习算法...

jliang3的博客 8万+

[ac自动机]zoj3228 Searching the String

Searching the StringTime Limit: 7 Seconds      Memory Limit: 129872 KB Little jay really hates to deal with string. But moondy likes it very much, and shes so mischievous that she often gives

幻想の天地 1366

CTK Plugin Framework插件框架学习1--Qt编译CTK

【代码】Qt编译CTK。

贝勒里恩的博客 7433

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Pku1037 A decorative fence 动态规划+递推

A decorative fenceTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3468 Accepted: 1122DescriptionRichard just finished building his new house. Now the only

幻想の天地 1354

SAP B1中文培訓教材_SDK

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

[数学-欧拉函数]Pku2478--Farey Sequence

http://acm.pku.edu.cn/JudgeOnline/problem?id=2478 Farey SequenceTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5575 Accepted: 1998DescriptionThe Fare

幻想の天地 1056

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

[动态规划]Pku1390 Blocks

BlocksTime Limit: 5000MS Memory Limit: 65536KTotal Submissions: 1497 Accepted: 567DescriptionSome of you may have played a game called Blocks. There are n blocks

幻想の天地 971

[AC自动机+dp]PKU 3691--DNA repair

http://acm.pku.edu.cn/JudgeOnline/problem?id=3691DNA repairTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 1469 Accepted: 650DescriptionBiologists f

幻想の天地 962

[数学-farey序列]Pku3374--Cake Share

http://acm.pku.edu.cn/JudgeOnline/problem?id=3374 Cake ShareTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2836 Accepted: 700DescriptionUpdog pre

幻想の天地 947

[动态规划,tsp问题]pku2288 Islands and Bridges

Islands and BridgesTime Limit: 4000MS Memory Limit: 65536KTotal Submissions: 4173 Accepted: 1008DescriptionGiven a map of islands and bridges that connect these isl

幻想の天地 920

[AC自动机]hdu2222 Keywords Search

Keywords SearchTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3406    Accepted Submission(s): 1177Problem DescriptionIn

幻想の天地 898

[动态规划]Zju1234--Chopsticks

ChopsticksTime Limit: 10 Seconds      Memory Limit: 32768 KB In China, people use a pair of chopsticks to get food on the table, but Mr. L is a bit different. He uses a set of three chopsticks

幻想の天地 818

vijos 不差钱 sbt的运用

 不差钱Buchaqian.pas描述:同学们一起看了小品《不差钱》,LX神突发奇想,想刁难一下十八居士,他让十八居士模拟一下点菜的过程。 输入:第一行为一个数price,表示价钱大于price的菜赵本山都不要。以下几行表示点菜的过程,每行两个整数p,np=1 表示在菜谱中添加一个价格为n的菜,这是第i个1号命令,这个菜的编号就是i,p=2 表示菜谱中第n号菜已

幻想の天地 763

[最短路spfa]pku1511-Invitation Cards

http://acm.pku.edu.cn/JudgeOnline/problem?id=1511 Invitation CardsTime Limit: 8000MS Memory Limit: 262144KTotal Submissions: 5784 Accepted: 1616DescriptionIn th

幻想の天地 713
上一篇: [并查集]Pku1703--Find them,Catch them
下一篇: [最大匹配]Pku3041--Asteroids
fstephen
博客等级 码龄18年 7粉丝 28原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值