HDU 6581 Vacation
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 910 Accepted Submission(s): 349Special Judge
Problem Description
Tom and Jerry are going on a vacation. They are now driving on a one-way road and several cars are in front of them. To be more specific, there are n cars in front of them. The ith car has a length of li, the head of it is si from the stop-line, and its maximum velocity is vi. The car Tom and Jerry are driving is l0 in length, and s0 from the stop-line, with a maximum velocity of v0. The traffic light has a very long cycle. You can assume that it is always green light. However, since the road is too narrow, no car can get ahead of other cars. Even if your speed can be greater than the car in front of you, you still can only drive at the same speed as the anterior car. But when not affected by the car ahead, the driver will drive at the maximum speed. You can assume that every driver here is very good at driving, so that the distance of adjacent cars can be kept to be 0. Though Tom and Jerry know that they can pass the stop-line during green light, they still want to know the minimum time they need to pass the stop-line. We say a car passes the stop-line once the head of the car passes it. Please notice that even after a car passes the stop-line, it still runs on the road, and cannot be overtaken.
Input
This problem contains multiple test cases. For each test case, the first line contains an integer n (1≤n≤105,∑n≤2×106), the number of cars. The next three lines each contains n+1 integers, li,si,vi (1≤si,vi,li≤109). It's guaranteed that si≥si+1+li+1,∀i∈[0,n−1]
Output
For each test case, output one line containing the answer. Your answer will be accepted if its absolute or relative error does not exceed 10−6. Formally, let your answer be a, and the jury's answer is b. Your answer is considered correct if |a−b|max(1,|b|)≤10−6. The answer is guaranteed to exist.
Sample Input
1 2 2 7 1 2 1 2 1 2 2 10 7 1 6 2 1
Sample Output
3.5000000000 5.0000000000
Source
2019 Multi-University Training Contest 1
Recommend
We have carefully selected several similar problems for you: 6590 6589 6588 6587 6586
中文题意
有n+1辆车在路口排队等着过红绿灯,可以假设一直都是绿灯,而且路太窄不能超车,后面的车赶上前面的车以后,可以和前车车尾距离为0,但不能推着前车走(哈哈),只能减速跟着。你排在最后一位。给出连上你那辆车,总共n+1辆的车头到红绿灯(题目里叫停车线)的距离、每辆车的车长、每辆车的最高速度,求你的车头到达红绿灯的最短时间。
吐槽
这么一个思维题,看到了题解总会觉得自己很蠢……但比赛中就是两个小时都搞不出来。我当时最想写的想法是,画出s-t图,然后从最前面(最后输入)的那辆车开始处理,画出车头的s-t图线,然后将该线上移车长的距离,变成车尾的线;之后处理第二辆,也是画出第二辆车头的s-t图线。第二辆的车头图线可能会在第一象限和第一辆车车尾的图线相交,说明第二辆被堵了,于是在交点处分段,左边取第二辆车的,右边取第一辆车的,以此类推,直到最后一辆,但是每加一条线,找交点的用时就是,跑一遍下来就是了,然后想到李超树维护线段,,然而不会李超树……
解题思路
比赛过程中,我校六个队,其中4个用了二分,而我只能想到吐槽里面那种贼复杂的,还写不出来。
二分
二分最少用时,假装每辆车相遇可以互相穿过去,然后得到每辆车经过那么多时间以后的位置,然后把队列捋一遍,从第二辆开始向后,如果后一辆的车头位置超到前一辆的车尾前面了,就把后一辆强行移动到前一辆屁股后面跟着。最后可以得到这段时间内自己那辆车的车头最远能走到哪里。如果还没到路口了,就增大用时;否则减小用时,精确度达到1e-7后输出答案。
线性
晚上dls直播讲题,直接上线性了,并没有二分。
我比赛结束听其他队说这题是二分的时候,疑惑过,二分出一个答案出来,要验证啊,总感觉验证过程就可以求出真正的答案了。赛后直觉还是挺敏锐的有卵用。
把所有车挤在一起,成一辆车厢不一样长的火车,然后我们开着自己的车,向前推动这辆火车,直到我们的车到达了红绿灯前(目标),然后计算每一辆车以自己的最高速度到达现在的位置的用时,取所有车里用时最长的(它会卡着后面的)。
源代码
二分的(线性的还没写不想写了)
#include<stdio.h>
int n;
double l[100010],s[100010],v[100010],vmn,pos[100010];
int main()
{
//freopen("test.in","r",stdin);
while(~scanf("%d",&n))
{
vmn=1e10;
for(int i=0;i<=n;i++)
scanf("%lf",l+i);
for(int i=0;i<=n;i++)
scanf("%lf",s+i);
for(int i=0;i<=n;i++)
scanf("%lf",v+i),vmn=v[i]<vmn?v[i]:vmn;
if(!n)
{
printf("%.10lf\n",s[0]/v[0]);
continue;
}
double left=0,right=s[0]/vmn;
while(right-left>=1e-7)
{
double mid=(left+right)/2;
for(int i=n;i>=0;i--)
pos[i]=s[i]-v[i]*mid;
for(int i=n-1;i>=0;i--)
if(pos[i]<pos[i+1]+l[i+1]) pos[i]=pos[i+1]+l[i+1];
if(pos[0]<0) right=mid;
else left=mid;
}
printf("%.10lf\n",left);
}
return 0;
}
HDU 6581 Vacation的更多相关文章
- hdu 6581 Vacation【思维】
原题链接: http://acm.hdu.edu.cn/showproblem.php?pid=6581 VacationTime Limit: 10000/5000 MS (Java/Others) ...
- 【HDU - 6581】Vacation(思维)
Vacation 题意 有n+1辆车,属性有长度l,距离终点的距离s,速度v问你最末尾的车到达终点的时间 Sample Input 1 2 2 7 1 2 1 2 1 2 2 10 7 1 6 2 1 ...
- hdu 6851 Vacation(思维+贪心)
传送门 •题意 有编号0到n,n+1辆车排队过红绿灯,从0到n离交通灯线越来越近 每辆车都有一个最大速度v,车身长度l,和离交通灯线的距离s, 一辆车头到达线则说明这辆车已到达线 如果一辆车前面没有紧 ...
- hdu多校第一场1004(hdu6581)Vacation 签到
题意:有n+1辆车,每辆车都有一定的长度,速度和距离终点的距离,第1-n辆车在前面依次排列,第0辆车在最后面.不允许超车,一旦后车追上前车,后车就减速,求第0辆车最快什么时候能到达终点? 思路:对于每 ...
- HDU6581 Vacation (HDU2019多校第一场1004)
HDU6581 Vacation (HDU2019多校第一场1004) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6581 题意: 给你n+1辆汽车, ...
- hdu 4869 Turn the pokers (2014多校联合第一场 I)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4670 Cube number on a tree(点分治)
Cube number on a tree Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/ ...
- HDU 5654 xiaoxin and his watermelon candy 离线树状数组 区间不同数的个数
xiaoxin and his watermelon candy 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5654 Description Du ...
- HDU校赛 | 2019 Multi-University Training Contest 1
2019 Multi-University Training Contest 1 http://acm.hdu.edu.cn/contests/contest_show.php?cid=848 100 ...
随机推荐
- LeetCode.876-链表的中间节点(Middle of the Linked List)
这是悦乐书的第337次更新,第361篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第206题(顺位题号是876).给定具有头节点的非空单链表,返回链表的中间节点.如果有两 ...
- 【Linux开发】如何更改linux文件的拥有者及用户组(chown和chgrp)
本文整理自: http://blog.163.com/yanenshun@126/blog/static/128388169201203011157308/ http://ydlmlh.iteye.c ...
- 深入理解java:1.2. 字节码执行引擎
执行引擎是Java虚拟机的核心组成部分之一. 首先,想想C++和Java在编译和运行时到底有啥不一样? 下图左边,C++发布的就是机器指令, 而下图右边Java发布的是字节码,字节码在运行时通过JVM ...
- CentOS 6.X Python 2.6升级到Python 2.7 【转】
前言:一些第三方框架为了降低复杂性,新的版本已经开始不支持旧版本的python,比如Django这个web框架1.8版本及以上仅仅只支持python2.7及以上版本(记忆中是这个1.8版本),pip安 ...
- Service-Oriented Architecture,SOA(转)
http://blog.csdn.net/WOOSHN/article/details/8036910 介绍: IT体系结构已非常成熟,它是一种成功处理典型IT问题的方法.体系结构中一个受到很大重视且 ...
- python 并发编程 查看进程的id pid与父进程id ppid
查看进程id pid 不需要传参数 from multiprocessing import Process import time import os def task(): print(" ...
- CentOS7创建本地源过程
1)使用yum安装http服务(主节点) yum -y install httpd 2)将httpd服务加入系统自启动服务并设置开机启动 systemctl start httpd #启动apache ...
- CF和OF的区别
进位标志CF和溢出标志OF的区别: 有符号数和无符号数只是认为的进行区分,计算机从来不区分有符号数和无符号数.对于运算的数来说,只要符合进位的情况,CF就置1.只要符合溢出的情况,OF就置1.但是后续 ...
- [pwnable.kr] - wtf
Q: I don't understand why my exploit is not working. I need your help. download : http://pwnable.kr/ ...
- P1397 [NOI2013]矩阵游戏(递推)
P1397 [NOI2013]矩阵游戏 一波化式子,$f[1][m]=a^{m-1}+b\sum_{i=0}^{m-2}a^i$,用快速幂+逆元求等比数列可以做到$logm$ 设$v=a^{m-1}, ...