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 ...
随机推荐
- RabbitMQ 安装步骤
RabbitMQ安装步骤 一.安装erlang 1.下载erlang wget https://packages.erlang-solutions.com/erlang-solutions-1.0-1 ...
- Eclipse连接SQL Server 2008数据库
一.准备材料 要能够使用数据库就要有相应的JDBC,所以我们要去Microsoft官网下载 https://www.microsoft.com/zh-cn/download/details.aspx? ...
- honpeyhonepy
2019.09.15 简历编辑功能: 2019.09.23 爬虫功能(智联招聘) 2.1 AI同步功能 2019.10.08 登录功能(包括普通用户登录.管理员.招聘人员) 2019.11.10 鉴权 ...
- 用Java构建一个简单的WebSocket聊天室
前言 首先对于一个简单的聊天室,大家应该都有一定的概念了,这里我们省略用户模块的讲解,而是单纯的先说说聊天室的几个功能:自我对话.好友交流.群聊.离线消息等. 今天我们要做的demo就能帮我们做到这一 ...
- markdown编辑器学习
markdown是一块文本编辑器,属于纯文本文件,可以使用任何编辑器打开.对于写作来说是一个好帮手,它的好处有很多,比如可以直接转成html,制作电子书等.今天开始学习一下这个神奇的编辑器.从今天起把 ...
- android——屏幕适配
一,基本概念 1:dip: 其实也就是dp,与像素无关 2:px: 像素,在安卓布局中不用px,因为每个手机像素不同,px显示的布局大小也就不同 3:dpi: 通俗点就是每英寸多少个像素,简称像素密度 ...
- Python爬虫之urllib.parse详解
Python爬虫之urllib.parse 转载地址 Python 中的 urllib.parse 模块提供了很多解析和组建 URL 的函数. 解析url 解析url( urlparse() ) ur ...
- 使用impala连接hive踩坑过程
一.打包镜像出错 docker build总是出错,如果你用的是python3.7,可以考虑使用python3.6版本 并且注意:选择thrift-sasl==0.2.1,否则会出现: Attribu ...
- python面向对象--类的装饰器
# def deco(obj): # print("=====",obj) # obj.x=1 # return obj # @deco#===> test = deco(t ...
- 008-流程控制 case 语句
流程控制 case 语句 与if...elif...else 语句一样都是多分支条件语句,不过if语句可以判断多种条件关系,case只能判断一种条件关系 [root@zabbix lianxi]# . ...