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的更多相关文章

  1. hdu 6581 Vacation【思维】

    原题链接: http://acm.hdu.edu.cn/showproblem.php?pid=6581 VacationTime Limit: 10000/5000 MS (Java/Others) ...

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

  3. hdu 6851 Vacation(思维+贪心)

    传送门 •题意 有编号0到n,n+1辆车排队过红绿灯,从0到n离交通灯线越来越近 每辆车都有一个最大速度v,车身长度l,和离交通灯线的距离s, 一辆车头到达线则说明这辆车已到达线 如果一辆车前面没有紧 ...

  4. hdu多校第一场1004(hdu6581)Vacation 签到

    题意:有n+1辆车,每辆车都有一定的长度,速度和距离终点的距离,第1-n辆车在前面依次排列,第0辆车在最后面.不允许超车,一旦后车追上前车,后车就减速,求第0辆车最快什么时候能到达终点? 思路:对于每 ...

  5. HDU6581 Vacation (HDU2019多校第一场1004)

    HDU6581 Vacation (HDU2019多校第一场1004) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6581 题意: 给你n+1辆汽车, ...

  6. hdu 4869 Turn the pokers (2014多校联合第一场 I)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

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

  8. HDU 5654 xiaoxin and his watermelon candy 离线树状数组 区间不同数的个数

    xiaoxin and his watermelon candy 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5654 Description Du ...

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

随机推荐

  1. git关联github远程仓库的问题

    git关联github远程仓库的时候,报fatal: remote origin already exists. 导致这个问题原因可能是之前关联的时候关联错了,再次关联就不行了. 解决办法是: 1.将 ...

  2. ContextLoaderListener错误

    在web.xml中添加如下配置 <context-param> <param-name>contextConfigLocation</param-name> < ...

  3. 最长上升子序列(LIS) Medium2

    JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two ...

  4. python字符串替换的2种方法

    python 字符串替换可以用2种方法实现:1是用字符串本身的方法.2用正则来替换字符串 下面用个例子来实验下:a = 'hello word'把a字符串里的word替换为python 1.用字符串本 ...

  5. 通过编写串口助手工具学习MFC过程——(十)UpdateData()用法和编辑框的赋值、取值

    通过编写串口助手工具学习MFC过程 因为以前也做过几次MFC的编程,每次都是项目完成时,MFC基本操作清楚了,但是过好长时间不再接触MFC的项目,再次做MFC的项目时,又要从头开始熟悉.这次通过做一个 ...

  6. django的模板的继承与导入

    1.模板继承 母版中需要继承的地方: {% block content %} {% endblock %} 对应的子版中文件最开头写: {% extends 'head_demo.html' %} 然 ...

  7. easyUI相关文件的引入

    引入以下内容: <head> <meta http-equiv="Content-Type" content="text/html; charset=u ...

  8. linux 深入应用 NFS

    以下实验大家用主机名来区分服务器端和客户端, 服务器端为 NFS_Server ip-192.168.1.4: 客户端为 NFS_Client ip-192.168.1.5: 实例一 将/tmp 分享 ...

  9. nodejs 操作 mongodb 数据库

    操作手册: npmjs.com 搜索: mongodb 使用官方的  mongodb 包来操作  https://github.com/mongodb/node-mongodb-native      ...

  10. Linux包安装及搭建服务

    IP地址:以·分隔成4部分,每部分在底层是以8位二进制存储 例:172.16.45.10/16(后面是子网掩码,表示网络地址是前面16位二进制) 网路地址:172.16.00 主机地址:172.16. ...