Codeforces Round #365 (Div. 2) C题(线性约束)

来源:互联网 发布:stc单片机iap选型 编辑:程序博客网 时间:2024/05/16 19:51

 
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 lines y = 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 time only x coordinates of its points are changing. Formally, after timet each of x 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 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 integersn, 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 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 21 23 14 33 41 4
Output
5.0000000000
Note

Following image describes initial position in the first sample case:


题意:有一个N边形的车,车速为v,你在原点,你的速度为u,想要到达(0,w),问人最快到达(0,w)点的时间。显然,车如果挡住你,你就不能走。

题解:

你走过去的情况就分两种:车对你没造成影响,车对你造成影响。

当车对你没造成影响又分两种情况:你的速度太快了,车的速度太快了。

分析这些情况1:你的速度太快了。车的任意一点都到达不了你的位置。既 xi/v>yi/u。

                      2:车的速度太快了,你到达 车任意一点在y轴的投影时,车已经过去了。既xi/v<yi/u.

                      3:车对你造成影响,此时你需要调整速度来躲车,我们可以换一种角度看,当车最后一个点通过的时候,你在内个点上,此时需要的时间就是车走xi 速度为v所需要的时间,再后面的路程(w-yi),你以速度u走。

1,2两种情况人都可以以最大速度u走。

代码:

#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <cmath>#include <set>#include <map>#include <vector>#include <queue>#include <algorithm>#define LL long long#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define maxn 300100using namespace std;int n;double v,u,x,y,w,ans;int main(){    cin>>n>>w>>v>>u;    bool flag,flagg;    flag=flagg=false;    ans=0;    for(int i=0;i<n;i++)    {        cin>>x>>y;        if(x/v>y/u)            flag=true;        if(x/v<y/u)            flagg=true;            ans=max(ans,x/v+(w-y)/u);    }    if(flag&&flagg)        printf("%.10lf\n",ans);    else        printf("%.10lf\n",w/u);}


 
0 0
原创粉丝点击