HDU 6581 Vacation

Posted wawcac-blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 6581 Vacation相关的知识,希望对你有一定的参考价值。

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 910    Accepted Submission(s): 349
Special 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 (1n105,n2×106), the number of cars.
The next three lines each contains n+1 integers, li,si,vi (1si,vi,li109). It‘s guaranteed that sisi+1+li+1,i[0,n1]
 

 

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 106.
Formally, let your answer be a, and the jury‘s answer is b. Your answer is considered correct if |ab|max(1,|b|)106.
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

 

 

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图线。第二辆的车头图线可能会在第一象限和第一辆车车尾的图线相交,说明第二辆被堵了,于是在交点处分段,左边取第二辆车的,右边取第一辆车的,以此类推,直到最后一辆,但是每加一条线,找交点的用时就是$O(n)$,跑一遍下来就是$O(n^2)$了,然后想到李超树维护线段,$O(nlog^2n)$,然而太菜了,不会李超树……

解题思路

  比赛过程中,我校六个队,其中4个用了二分,而我只能想到吐槽里面那种贼复杂的,还写不出来。

二分

  二分最少用时,假装每辆车相遇可以互相穿过去,然后得到每辆车经过那么多时间以后的位置,然后把队列捋一遍,从第二辆开始向后,如果后一辆的车头位置超到前一辆的车尾前面了,就把后一辆强行移动到前一辆屁股后面跟着。最后可以得到这段时间内自己那辆车的车头最远能走到哪里。如果还没到路口了,就增大用时;否则减小用时,精确度达到1e-7后输出答案。

线性

  晚上dls直播讲题,直接上线性了,并没有二分。

  我比赛结束听其他队说这题是二分的时候,疑惑过,二分出一个答案出来,要验证啊,总感觉验证过程就可以求出真正的答案了。赛后直觉还是挺敏锐的有卵用

  把所有车挤在一起,成一辆车厢不一样长的火车,然后我们开着自己的车,向前推动这辆火车,直到我们的车到达了红绿灯前(目标),然后计算每一辆车以自己的最高速度到达现在的位置的用时,取所有车里用时最长的(它会卡着后面的)。

源代码

二分的(线性的还没写)

 1 #include<stdio.h>
 2 
 3 int n;
 4 double l[100010],s[100010],v[100010],vmn,pos[100010];
 5 
 6 int main()
 7 
 8     //freopen("test.in","r",stdin);
 9     while(~scanf("%d",&n))
10     
11         vmn=1e10;
12         for(int i=0;i<=n;i++)
13             scanf("%lf",l+i);
14         for(int i=0;i<=n;i++)
15             scanf("%lf",s+i);
16         for(int i=0;i<=n;i++)
17             scanf("%lf",v+i),vmn=v[i]<vmn?v[i]:vmn;
18         if(!n)
19         
20             printf("%.10lf\n",s[0]/v[0]);
21             continue;
22         
23         double left=0,right=s[0]/vmn;
24         while(right-left>=1e-7)
25         
26             double mid=(left+right)/2;
27             for(int i=n;i>=0;i--)
28                 pos[i]=s[i]-v[i]*mid;
29             for(int i=n-1;i>=0;i--)
30                 if(pos[i]<pos[i+1]+l[i+1]) pos[i]=pos[i+1]+l[i+1];
31             
32             if(pos[0]<0) right=mid;
33             else left=mid;
34         
35         printf("%.10lf\n",left);
36     
37     return 0;
38 

 

以上是关于HDU 6581 Vacation的主要内容,如果未能解决你的问题,请参考以下文章

HDU - 6581 Vacation (贪心+思维+物理)

HDU 6581 Vacation

2019杭电多校第一场hdu6581 Vacation

2019年7月做题记录

hdu--1258--Sum It Up(Map水过)

智能卡:非易失性存储器的状态已更改 - 0x6581