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. 利用yum创建本地仓库与网络源

    一.创建本地yum仓库 1.cd /etc/yum.repos.d/ 2.创建配置文件:[root@li yum.repos.d]# vim local.repo 3.写入配置信息并保存 [li]na ...

  2. IP地址转换函数——inet_pton inet_ntop inet_aton inet_addr inet_ntoa

    inet_pton NAME     inet_pton - 将 IPv4 和 IPv6 地址从点分十进制转换为二进制 SYNOPSIS #include <arpa/inet.h> in ...

  3. <<用法

    数据移位运算符,左移几位,如:x=i<<4;就是将i的值左移4位(放大2的4次方)后,赋给x,若i=2,则X=32.

  4. 红帽学习笔记[RHCSA] 第八课[Nice值、时间同步、RPM与Yum软件安装]

    第八课 nice值 什么是nice值 给进程设置的优先级就是nice.nice的范围是-20~20.nice值越小占用的系统资源就越多,就是这个进程不nice. 如何查看nice值 # 使用top命令 ...

  5. 大数据平台CentOS7+CDH5.12.1集群搭建

    1.CM(Cloudera Manager)介绍 1.1 简介 Cloudera Manager是一个拥有集群自动化安装.中心化管理.集群监控.报警功能的一个工具,使得安装集群从几天的时间缩短在几个小 ...

  6. HDU1181 题解(Floyd最短路)

    题面: 变形课 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...

  7. Python 多列数据存储

    zip()函数 zip函数可以把多个列表相加成一个tuple(元组) a = [1,2,3,4] b = [11,22,33,44] c = [111,222,333,444] A = list(zi ...

  8. Ubantu创建热点并共享——2019年5月10日更新

    只需要两步,参考以下两篇文章: ubuntu16.04上安装配置DHCP服务的详细过程 Ubuntu18.04 创建与编辑热点的方法

  9. winform 自定义控件(高手)

    高手推荐:https://www.cnblogs.com/bfyx/p/11364884.html   c#Winform自定义控件-目录   前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件 ...

  10. python 调用dll 动态链接库 结构体参数及回调函数等示例

    结构体示例: 这里是 C 代码的部分,主要是结构体的声明和回调函数定义. // 新版本定义 typedef enum { DevCard, DevLocator, DevReader } DevTyp ...