题面
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 i th 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 .
Input This problem contains multiple test cases.
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 .
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
|
题意
提供n+1辆车的车身长度、离终点线的距离和最大速度。每辆车不能超车。问:0号车通过终点线的时间?
题目链接
参考
《第一场多校题解》
分析
提供n+1辆车的车身长度、离终点线的距离和最大速度。每辆车不能超车。问:0号车通过终点线的时间?
0号在理想情况下的最少时间(最快速度通过终点线),即没有与其他车相撞。即0号车的s/v
考虑撞车的结果,不考虑撞车的过程。
0号车通过终点线时,一定是被编号1-n中的编号为x的车堵着,0号车以x号车的速度通过终点线。则根据x号车到终点线的距离s,1-x号车总的车身长度得到距离 ,除以速度
。得到0号车被x号车堵着通过终点线的时间。
依次试探x=1,2,3,,,,,,,n
取所有时间里最慢的,即最大值。
因为假如可以以更少的时间通过终点线,则0号车可以穿过1-x号车中的一些车,所以不可行。
程序分析
car_length:1-x号车的总的车身长度。
程序
#include<stdio.h>
#include<iostream>
using namespace std;
#define maxn 100005
struct Car
{
double s,l,v;
}car[maxn];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<=n;i++)
scanf("%lf",&car[i].l);
for(int i=0;i<=n;i++)
scanf("%lf",&car[i].s);
for(int i=0;i<=n;i++)
scanf("%lf",&car[i].v);
double answer=car[0].s/car[0].v;
double car_length=0;
for(int i=1;i<=n;i++)
{
car_length+=car[i].l;
answer=max(answer,(car_length+car[i].s)/car[i].v);
}
printf("%.10lf\n",answer);
}
return 0;
}
2019年07月23日 09:32:23