zoukankan      html  css  js  c++  java
  • 【23.15%】【codeforces 703C】Chris and Road

    time limit per test2 seconds
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    And while Mishka is enjoying her trip…

    Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris’ best friend.

    Once walking with his friend, John gave Chris the following problem:

    At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.

    There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.

    Please look at the sample note picture for better understanding.

    We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).

    You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.

    Input
    The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v,  u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.

    The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.

    Output
    Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn’t exceed 10 - 6.

    Example
    input
    5 5 1 2
    1 2
    3 1
    4 3
    3 4
    1 4
    output
    5.0000000000
    Note
    Following image describes initial position in the first sample case:
    这里写图片描述

    【题解】

    题意:你要从(0,0)走到(0,w),右方有一部多边形的车从右往左走过来;你要花最少的时间走到(0,w),且不被车撞。
    做法:
    对于所有的点。获取->当你和车上的这个点(px,py)的坐标的纵坐标相同的时候,车上的这个点的横坐标为多少;
    设你和这个点的纵坐标相同时所花的时间为t=py/u
    则车上这个点的横坐标px’变为px-t*v
    获取车上的所有点的px’中的max和min值
    分类讨论:
    1.最简单的。就是直接高速走过去都不会被车撞->即到达(0,0)->(0,w)这条线段上的所有点的时候。车子的所有点都在你到达之前就全都走过了。或者全都还没到达.
    ->对应min >=0 || (min <0 && max <=0)的情况
    答案当然就是w/u了
    2.可能会被撞.
    即min <0 but max >0
    就需要减速了。
    需要怎么减速呢?我们把它理解为停顿一下;
    这里写图片描述
    对于我们求出来的max,它对应上图的情况。(车子从右往左移动对应人从左下往左上);
    即我们全速前进和从下往上数第二个波峰的纵坐标相同的时候.横坐标的差值.因为这个差值的存在,所以我们会被车撞。
    当前第一个波峰的时候也会被车撞。
    但是显然第二个波峰造成的影响需要修正的地方更大;
    那么要怎么修正呢?
    首先我们可以确定。我们到达第二个波峰的时候(虽然会被撞)但是时间是最短的。因为是全速前进的。
    那么我们想保留这个最快的过程应该要怎么样呢.
    这样理解:
    这里写图片描述
    即把这条线段往右平移一段。这样我们全速前进到和第二个波峰的纵坐标相同的时候。刚好碰到那个波峰(题目设定这样不算被撞)。到了波峰之后只要全速前进就可以到终点了。
    那这个平移代表什么呢?
    当然就是在起点等了一段时间->max/v
    这里写图片描述
    所以总的时间就是
    max/v+w/u;
    这里你们可能会想到:那第一个波峰呢?
    这里写图片描述
    实际上我们是不会碰到第一个波峰的。因为我们在处理的时候已经知道AB这段长度max是大于d1的了。
    而我们和W和B点的纵坐标相同的时候,经过的点分别是Q和A
    如果我们向右平移了max个单位。max>d1则肯定我们走平移过的路线之后和W的纵坐标相同的时候,肯定是在W的右边的.也就是说W这个点肯定已经走到x=0的左边去了。
    多想想吧.
    可能有人会想到这种情况。
    这里写图片描述
    这样不就不对了吗???
    但是注意车的点的纵坐标是大于0的!
    所以图中的A点是不合法的.
    再多说几句吧:
    设max对应的点,即倒数第二张图的B点。
    我们肯定是要到那个坐标的;
    而我们得知到那个坐标之后你得等那个B点从你身前走过去,而你是全速前进的,所以到达B点的最短时间
    肯定就是yb/u了但是你得等这个B点走过去;这又是不得不等的一段时间;所以我们干脆就在起点等这段时间过去,然后马上以最高时速到达这个B点,这样肯定满足时间最短,且这个B点刚好走到左边去了,过后就是康庄大道了。可以一直以高速前进.
    综上这个方法是可行的。
    别想了,我的脑子。就是这样了。睡觉吧。
    (博主是强迫症患者TAT)

    #include <cstdio>
    #include <algorithm>
    
    using namespace std;
    
    const double INF = 1e15;
    int n;
    double w, v, u;
    double mi=INF, ma = 0,ans;
    
    int main()
    {
        scanf("%d%lf%lf%lf", &n, &w, &v, &u);
        for (int i = 1; i <= n; i++)
        {
            int x, y;
            scanf("%d%d", &x, &y);
            double dis = x - y/u*v;
            ma = max(ma, dis);
            mi = min(mi, dis);
        }
        if (mi >= 0)
            ans = w / u;
        else//mi <0
            if (ma<= 0)
                ans = w / u;
            else//ma > 0
                ans = ma / v + w / u;
        printf("%.10lf
    ", ans);
        return 0;
    }
  • 相关阅读:
    Silverlight:拖动滚动条控制媒体播放
    黑马程序员第一阶段3.面向对象第5天
    黑马程序员第一阶段2.java编程基础第4天
    黑马程序员第一阶段2.java编程基础第2天
    黑马程序员第一阶段2.java编程基础第3天
    黑马程序员第一阶段3.面向对象第6天
    黑马程序员第一阶段3.面向对象第8天
    黑马程序员第一阶段3.面向对象第7天
    黑马程序员第一阶段1.Java开发前奏第1天
    hdu 1133
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7632159.html
Copyright © 2011-2022 走看看