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 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.

Input

The first line of the input contains four integers nwvu (3 ≤ n ≤ 10 0001 ≤ w ≤ 1091 ≤ 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:



题意:有一个n边形的汽车向以速度v向x轴负方向移动,给出零时时其n个点的坐标。并且有一个人在(0,0)点,可以以最大速度u通过w宽的马路,到达(0,w)点。现在要求人不能碰到汽车,人可以自己调节速度。问人到达马路对面的最小时间是多少?


题解:一共有三种情况:

①. 人以最大速度u前进时,汽车的速度太慢,任意一点都到达不了人的位置

②.人以最大速度u前行时,汽车的速度太快,在人达到之前汽车的任意一点都已经通过了y轴

③.人以最大速度u前进时,会与汽车相撞,需要调整速度躲避汽车


上面三种情况,①②两种都可以直接以最大速度u通过马路。第③种1情况,我们可以在汽车对人速度影响最大的点通过时到达那个点的位置,然后全速u走到终点。


看着很麻烦,想通了就是水题啊,我真的很智障啊


代码如下:


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 10010
double x[maxn],y[maxn];
int main()
{
	int n,i;
	double w,v,u;
	while(scanf("%d%lf%lf%lf",&n,&w,&v,&u)!=EOF)
	{
		int flag1=1,flag2=1;
		double ans=0;
		for(i=0;i<n;++i)
		{
			scanf("%lf%lf",&x[i],&y[i]);
			if((x[i]/v)>(y[i]/u))
				flag1=0;
			if((x[i]/v)<(y[i]/u))
				flag2=0;
			ans=max(ans,x[i]/v+(w-y[i])/u);
		}
		if(flag1+flag2>0)//人以最大速度u前进,不会与车相撞 
			printf("%.10lf\n",w/u);
		else printf("%.10lf\n",ans);
	}
	return 0; 
} 



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值