Codeforces 703C Chris and Road(转换参考系)

C. Chris and Road
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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 linesy = 0 andy = w, there is a bus moving, presented as a convex polygon ofn vertices. The bus moves continuously with a constant speed ofv in a straight Ox line in direction of decreasingx coordinates, thus in timeonly x coordinates of its points are changing. Formally, after timet each ofx coordinates of its points will be decreased byvt.

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 exceedingu. Thus the pedestrian can move only in a straight lineOy in any direction with any speed not exceedingu 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 liesstrictly 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 integersxi andyi ( - 109 ≤ xi ≤ 109,0 ≤ yi ≤ w) — coordinates ofi-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 exceed10 - 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:


题目大意:

    人从原点出发,可以以小于等于u的任意速度向上或向下运动,一个n边型的车以恒定的速度v向左运动(竟然有车长得这么奇葩),给出车各个点的初始坐标。求人在不被车撞的前提下最快到达对面的时间。


解题思路:

    一共有两种情况。

    第一种情况、人开始就一直以u的速度往前走,没有被车撞。那么时间最短就是w/u。

    第二种情况,人要在车后面过去。那么为了时间最短人一定要安全的前提下尽量贴着车走才能时间最短。

    我们可以将问题看成车不动,人先水平移动一段距离,再沿着斜率为u/v的直线运动。那么就变成了平移直线使其与车相切。由于车的每条边都是直线,那么切点一定在顶点上。我们只要枚举全部顶点,一个点和一个斜率就可以确定一条直线。我们只要找到最左边和最右边一条直线则这两条直线与车一定是相切的。这时切线与x轴交点如果在原点左边,那么就是第一种情况。否则是第二种情况。在我们新建的模型下时间就非常好求。具体见代码。


AC代码:

#include <algorithm>
#include <cstdio>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8

int n,w,v,u;

int main()
{
    scanf("%d%d%d%d",&n,&w,&v,&u);
    double vv=u*1.0/v,left_most=INF,right_most=0;
    for(int i=0;i<n;++i)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        left_most=min(left_most,x-y/vv);//保存最左边切线与x轴交点
        right_most=max(right_most,x-y/vv);//保存最右边切线与x轴交点
    }
    printf("%.10f\n",left_most>-eps?w*1.0/u:right_most/v+w*1.0/u);
    
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值