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 nvertices. 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.
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.
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.
5 5 1 2
1 2
3 1
4 3
3 4
1 4
5.0000000000
Following image describes initial position in the first sample case:
大体题意:
一个行人刚开始位于(0,0),他要到达(0,w),还有一个车,他是个多边形,告诉你车每个顶点的位置,告诉你车的速度是v匀速向X轴负半轴行驶,人的速度是0~u,可以随时改变速度!求出人要想不被车撞到,(严格在对变形内部才算撞到)。至少花多久到对面?
思路:
想明白了就是一道水题!
可以枚举车的所有顶点(x,y),求出当人走到(0,y)时,(x,y)顶点走到了距离Y轴还多远,这样把这个距离的最大值和最小值求出来,Max,Min,
如果Min大于0,表示最能撞到人的顶点都在人的右边,那这个车肯定撞不到人,直接就是w/u!
如果Min小于0,并且Max 大于0,那么你必须等车会撞到你的点过去后再走,答案就是Max/v + w/u!
如果Max也小于0,那么说明这个车开的太快了~,你还没走多久,他已经过去了,这时输出w/u!
就这三种情况!
可以加上精度!
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1.0);
int main(){
double n,w,v,u;
scanf("%lf %lf %lf %lf",&n,&w,&v,&u);
double Min = inf*1.0;
double Max = -inf*1.0;
for (int i = 0 ; i < n; ++i){
double x,y;
scanf("%lf %lf",&x,&y);
Min = min(Min,x-(y*v/u));
Max = max(Max,x-(y*v/u));
}
// printf("%lf\n",Max);
if (Min >= -eps) printf("%.15lf\n",w/u);
else if (Max >= -eps)printf("%.15lf\n",Max/v + w/u);
else printf("%.15lf\n",w/u);
return 0;
}