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≤,∑n≤2×
), the number of cars.
The next three lines each contains n+1 integers, li,si,vi (1≤si,vi,li≤). 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 .
Formally, let your answer be a, and the jury's answer is b. Your answer is considered correct if ≤.
The answer is guaranteed to exist.
学习了大佬的思路。。。。。。。一切尽在不言中
第一种情况:很好理解,若是最后的车到达终点之前没有和其他车贴在一起,就是s[0]/v[0];
第二种情况:如果在到达终点之前与前面的车贴在一起那么可能
与它前面一辆贴在一起,或者与它前面两辆贴在一起,或者更多辆
1,2,3,。。。。
好当与前面几辆贴在一起走到终点的速度就是这这几辆车最前面的那辆的速度
假设与前i辆贴在一起 答案是 (l1 + l2 + l3...+li)/v[i];
所有就枚举以每辆车速度到达终点的时间,取最大即可
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int s[N],v[N],l[N];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i = 0;i <= n;i++)
scanf("%d",&l[i]);
for(int i= 0;i <= n;i++)
scanf("%d",&s[i]);
for(int i = 0;i <= n;i++)
scanf("%d",&v[i]);
double ans = s[0]*1.0/v[0];
ll sum = 0;
for(int i = 1;i <= n;i++)
{
sum+=l[i];
ans = max((sum+s[i])*1.0/v[i],ans);
}
printf("%.10f\n",ans);
}
return 0;
}