Codeforces round #365 (Div.2) C

Source: Internet
Author: User
C. Chris and Road time limit per test 2 seconds memory limit per test megabytes input standard input output standard o Utput

And while Mishka is enjoying she trip ...

Chris was a little brown bear. No one knows, where and when he is met Mishka, but for a long time they is together (excluding her current trip). However, best friends is 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 Movin G, 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 is changing. Formally, after Time t each Of x coordinates of its points would 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 con Necting points (0, 0) and (0, W) with an any speed not exceeding U. Thus The pedestrian can move only on a straight line Oy in any direction with any speed not exceeding u and not leaving th E Road borders. The pedestrian can instantly change him speed, thus, for example, he can stop instantly.

Better understanding at the sample note.

We Consider the pedestrian is hits by the bus, if at any moment the point he's located in lies strictly inside the bus pol Ygon (this means so if the point lies on the polygon vertex or on its edge, the pedestrian are not hit by the bus).

You is 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 N OT to is hit by the bus. Input

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, the polygon is non-degenerate. Output

Print the single real t-the time the pedestrian needs to Croos, the road and not to being 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:

First, the left side of the polygon can be converted to the right shift of pedestrians, that is, pedestrians have a right fixed speed and upward variable speed, then, the line of people walking upward is a limited slope of the line, obviously there is a principle, "bottom" point will affect the path, for each point, according to slope from small to large discussion, bad description, Look at the code:

#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; }



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.