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:

题意:

  在平面上有一个X-Y轴,一人正立于(0, 0)点,他想到达(0, w)点,且只能沿着竖直的向Y正半轴移动,最大速度为 u,可以随时在0 ~ u 之间调整自己的速度,在y = 0 和 y = w之间存在一条路,在路上存在一辆 bus,出人意料,这辆 bus 是一个不规则的凸 n 边形,其只能平行于 X 轴以速度 v 匀速向 X 负半轴移动.人在行动时能被车撞的条件是某时某刻人的坐标在车的坐标所围成的区域之内,也就是说允许与车擦边,给你n, w, v, u, 以及这个奇形怪状的车的 n 个顶点的坐标,问人达到目的地的最短时间.

思路:多校训练赛时就看到过这道题,当时看到题后一脸懵懂,车的形状不固定,根本没法求啊,完全想不到,

下面是别人的思路,分三种情况。

情况1:人以最大速度 u ,直接横穿马路,此时车还处于 Y 轴右侧,未触及Y轴,即很幸运的没被车撞.满足这个情况的条件是对于每一点(xi, yi),其与 Y 轴的交点是(0, yi),人到达此点的时间(yi / u)大于等于车到达此点的时间(xi / v);即对于所有的 i,满足 yi / u >= xi / v,也就是说在车到达此点之时,人已经先于车过去了.

    情况2:人同样以最大速度 u 横穿马路,此时车已处于 Y 轴左侧,即车在人之前已经过去,那么人肯定就不会被车撞了.满足这个情况的条件是对于每一点(xi, yi),设其与 Y 轴的交点是(0, yi),人到达此点的时间(yi / u)小于等于车到达此点的时间(xi / v);即对于所有的 i,满足 yi / u <= xi / v,也就是说在人到达某一点之前,车已先于人通过此点.

    情况3:人要是想以最大速度 u 通过马路,会在某时某刻被撞扑街.那么此时最优的办法就是从一开始,先尽可能远的到达某点 X 处(设时间为t1),在此处等待车过去之后再以最大速度通过(设时间为t2).如果车上某点是(xi, yi),那么设 X 这点是(0, yi),人到达这点的时间是 yi / u,车到达这点的时间是 xi / v,如果满足这种情况,那么说明 xi / v > yi / u,所以t1取较大值为 xi / v,则t2 为 (w - yi) / u,总时间t = t1 + t2.至于此点怎么寻找,因为是否被撞,关键是看车的顶点,那么在O(N)的时间复杂度内枚举每个顶点,取最大值就好了.

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,i;
	double u,v,w,x,y;
	scanf("%d%lf%lf%lf",&n,&w,&v,&u);
	double t=-1;
	int fast=0;
	int slow=0;
	for(i=0;i<n;i++)
	{
		scanf("%lf%lf",&x,&y);
		if(x/v<y/u)//存在一点不符合情况1 
		fast=1;
		if(x/v>y/u)//存在一点不符合情况2 
		slow=1;
		t=max(t,x/v+(w-y)/u);
	}
	if(!fast||!slow)
	t=w/u;
	printf("%lf\n",t);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值