codeforces round #365 (div.2) C

本文介绍了一个模拟行人避开移动障碍物(如巴士)的问题。行人必须从道路的一侧到达另一侧,同时避免被移动的障碍物碰撞。通过计算不同速度和位置下的最优策略,确保行人安全穿越。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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:

首先,可以把多边形的左移转化为行人的右移,即行人有一个向右的定速度和向上的不定速度,那么,即行人向上行走的路线为一条斜率有限制的线,显然存在一个原则,“最下面”的点会影响路径,对于每个点,按斜率由小到大讨论,不好描述,看代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#define inf 1e9
using namespace std;
const int maxn=10005;
struct point{
	int x,y;
	double b,k;
};
point bus[maxn];
double k0;
int n,w,v,u;
bool cmp(point a,point c){
	return a.k<c.k;
}
int main(){
	int i,j;
	double ans=0;
	double x=0,y=0;
	cin>>n>>w>>v>>u;
	k0=double(u)/double(v);
	for(i=1;i<=n;i++){
		scanf("%d%d",&bus[i].x,&bus[i].y);
		bus[i].b=double(bus[i].y)-k0*double(bus[i].x);
		if(bus[i].x<=0)bus[i].k=inf;
		else bus[i].k=double(bus[i].y)/double(bus[i].x);
	}
	sort(bus+1,bus+1+n,cmp);
	/*cout<<"k0:"<<k0<<endl;
	for(i=1;i<=n;i++){
		cout<<"bus:"<<i<<"  x:"<<bus[i].x<<"  y:"<<bus[i].y<<"  k:"<<bus[i].k<<endl;
	}*/
	if(bus[n].k<=k0){
		printf("%.8lf\n",double(w)/double(u));
		return 0;
	}
	for(i=1;i<=n;i++){
		if(bus[i].x<=x)continue;
		if(double(bus[i].y-y)/double(bus[i].x-x)<k0){
			x=bus[i].x;
			y=bus[i].y;
		}
	}
	x=(double(w)-y)/double(u)+x/double(v);
	printf("%.8lf\n",x);
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值