HDU 6581 - Vacation 2019多校联赛 第一场

                                                 Vacation

                       Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
                                          Total Submission(s): 1327    Accepted Submission(s): 547
                                                                                 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 s0from 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

题意解析:

汤姆和杰瑞现在在一条单行道上行驶,前面有 n 辆车。更具体地说,他们前面有 n 辆车。第 i 辆车长l_{i},头部距停车线s_{i},最大速度为v_{i}。汤姆和杰瑞驾驶的车长l_{0},距停车线s_{0},最大速度为v_{0}

假设它总是绿灯。然而,由于道路太窄,只能单车通过。即使你的速度比前面的车快,你仍然只能以和前面的车一样的速度行驶。如果不受前方车辆的影响,驾驶员将以最大速度行驶。这里的司机都很擅长驾驶,这样相邻车辆的距离就可以保持在0。

他们想知道通过停车线所需的最短时间。可以认为,一旦车头经过停车线,一辆车就通过了,注意,即使汽车经过停车线,它仍然在路上行驶,不能超车。

思路分析:

由于我们是要计算本车通过停止线的时间,那其实本车通过情况有两种:

  1. 前方车辆不会影响本车速度,直接可以以本车速度走到最后
  2. 本车需要跟车行驶,以前车速度行驶直到出线

所以,我们需要计算出每个车按原速度到达停止线的时间,而因为汤姆的车一定是最后才通过的,所以取最大值即可:                                                                              ans=max\left ( ans,\frac{\sum_{j=1}^{i}\left ( l_{i} \right )+s_{i}}{v_{i}} \right )

即为本车车头通过停止线的时间

代码篇:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int l[100010], v[100010], s[100010];
int main()
{
    ios::sync_with_stdio(false);
    int n;
    double ans = 0;
    while(cin >> n)
    {
        ans = 0;
        for(int i = 0; i <= n; i++)  ///输入数据
            cin >> l[i];
        for(int i = 0; i <= n; i++)
            cin >> s[i];
        for(int i = 0; i <= n; i++)
            cin >> v[i];
        long long dis = - l[0];
        for(int i = 0; i <= n; i++)  ///计算每个车到达的时间
        {
            dis += l[i];
            ans = max(ans, 1.0 * (dis + s[i]) / v[i]);
        }
        printf("%.7f\n", ans);
    }
    return 0;
}

 

OVER!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值