zoukankan      html  css  js  c++  java
  • HDU

    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 nn cars in front of them. The ii th car has a length of lili , the head of it is sisi from the stop-line, and its maximum velocity is vivi . The car Tom and Jerry are driving is l0l0 in length, and s0s0 from the stop-line, with a maximum velocity of v0v0 .
    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 00 .
    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 nn (1≤n≤105,∑n≤2×1061≤n≤105,∑n≤2×106 ), the number of cars.
    The next three lines each contains n+1n+1 integers, li,si,vili,si,vi (1≤si,vi,li≤1091≤si,vi,li≤109 ). It's guaranteed that sisi+1+li+1,∀i∈[0,n−1]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−610−6 .
    Formally, let your answer be aa , and the jury's answer is bb . Your answer is considered correct if |ab|max(1,|b|)≤10−6|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+1辆车,每个车有三个属性分别为车长、车速以及到停车线的距离。开始时每辆车同时启动,如果一辆车的车速大于前车的车速则只能跟在前车后面,否则的话全速前进。问最后一辆车车头何时到达停车线。

    所有车一共分为两种情况:自由前进以及跟车。如果最后一辆车是自由前进,则我们可以直接计算答案,否则的话一定是一坨车(设为k辆)一起走,这时其实我们已经能够根据这坨小火车车头的属性以及这一坨车车头到车尾的长度计算出答案了,因为此课排头车相当于自由前进,而所有车又是同一时刻发车的,因此时间都是同步的,当排头车到达停车线时,最后一辆车距离停车线还有前面k-1辆车的距离,故此时的答案可以根据前缀和直接计算出来。这仅仅是一种情况,对于全部车辆,依次枚举第i辆车作为那一坨小火车的车头,答案即为这n+1(别忘了最后一辆车自由行驶也要算进去)种情况的最大值。为什么是最大值呢?可以这么考虑:前面车的速度是限制答案的关键。当出现更大的时间,说明某些车的行驶受到了限制,并且答案应该服从这些限制。不妨假设最后一辆车自由行驶,如果最后一辆车跟在倒数第二辆车后面计算得出的答案更大,说明自由行驶不成立,最后一辆车的速度小于倒数第二辆车的速度…同理可以类比,因此最终的答案取最大。

    #include <bits/stdc++.h>
    using namespace std;
    struct car
    {
        int l, s, v;
    } c[100005];
    int n;
    double ans = 0;
    int sum[100005] = {0};
    int main()
    {
        while(scanf("%d", &n) != EOF)
        {
            ans = 0.0;
            for(int i = 0; i <= n; i++)
            {
                scanf("%d", &c[i].l);
                if(i > 0) sum[i] = sum[i - 1] + c[i].l;
            }
            for(int i = 0; i <= n; i++)
            {
                scanf("%d", &c[i].s);
            }
            for(int i = 0; i <= n; i++)
            {
                scanf("%d", &c[i].v);
            }
            c[n+1] = c[0];
            for(int i = 1; i <= n; i++)//枚举从哪辆车开始堵 
            {
                ans = max(ans, 1.0 * (c[i].s + sum[i]) / c[i].v);
            }
            ans = max(ans, 1.0 * (c[n + 1].s + sum[n + 1]) / c[n + 1].v);
            printf("%.10lf
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    acm 总结之大数加法
    hdu 1004
    hdu 1887
    hdu 2007
    hdu 2004
    ACM总结之 A+B problem 总结
    nyoj_42_一笔画问题_201403181935
    最短路径--Floyd算法
    最短路径—Dijkstra算法
    nyoj_114_某种序列_201403161700
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13326525.html
Copyright © 2011-2022 走看看