Vacation
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2273 Accepted Submission(s): 1018
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 (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
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=6581
题意:
有n+1辆车,告诉你每辆车的距离终点的长度、车身的长度和最高驾驶速度。在行驶的过程中不允许超车(即后面的车最多也只能车头贴着前一辆车的车尾,然后以同样的速度前进),问这最后一辆车驶过终点需要多长时间(与答案误差不超过1e-6)。
题解:
最终通过停止线的时候,一定是一个车后面堵着剩余所有的车,那么影响时间的就只有最前面这辆车,所以对于每一辆车, 假设是它是和 0 车堵在一起的最靠前的一辆车,那么可以计算出一个值,所有的车的计算 值的最大值就是答案。计算的时候一定不要忘了算上这堵在一起的一堆车的车身长度,因为最后一辆车的车头通过终点,才算结束。
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a,num) memset(a,num,sizeof(a))
const int maxn = 1e6+5;
ll t,n,temp;
int num[maxn];
int l[maxn],s[maxn],v[maxn];
int main() {
while(~scanf("%d",&n)) {
for(int i = 0; i < n+1; i++) {
scanf("%d", &l[i]);
}
for(int i = 0; i < n+1; i++) {
scanf("%d", &s[i]);
}
for(int i = 0; i < n+1; i++) {
scanf("%d", &v[i]);
}
double ans = s[0]*1.0/v[0];
temp = 0;
for(int i = 1; i<n+1; i++) {
temp += l[i];
ans = max((temp+s[i])*1.0/v[i],ans);
}
printf("%.10f\n",ans);
}
}