#P4498. Optimal Race Path
Optimal Race Path
Optimal Race Path
In this problem, you are given an infinite sandy plane and a race track that is defined by a non-self-intersecting polyline consisting of n line segments. The track starts at the origin (0,0) and is formed by n+1 vertices. The car can travel along the track at a speed of (v_a) and off the track (on sand) at a speed of (v_b), with (v_a \ge v_b). Note that the car is allowed to move in either direction (i.e. reverse is allowed) when on the track. However, switching between on-track motion and off-track motion can only occur at the vertices of the polyline.
Your task is to help the racer determine the minimum time required to travel from the starting point (0,0) to the finish (the last vertex of the track). When traveling along the track from one adjacent vertex to the next, the time is computed as: [ \text{time} = \frac{d}{v_a}, \quad \text{where } d \text{ is the Euclidean distance.} ] For any two (not necessarily consecutive) vertices, if the racer decides to leave the track and travel on sand, the time is computed as: [ \text{time} = \frac{d}{v_b}. ]
Find the minimum travel time from the start to the finish knowing that the racer may combine both types of travel.
Input Format:
- The first line contains three integers: n, v_a, and v_b, where 1 ≤ n.
- Each of the next n lines contains two integers x and y indicating the coordinates of the successive vertex. (Note that the starting vertex is (0, 0) and is not given in the input.)
Example:
Input: 2 10 5 10 0 20 0 Output: 2.000000
inputFormat
Format:
n v_a v_b x1 y1 x2 y2 ... xn yn
The first line contains three integers, where n is the number of segments in the track, and v_a and v_b are the speeds on track and on sand respectively. The following n lines each contain two integers representing the coordinates of each vertex (except the starting vertex (0,0)).
outputFormat
Format:
T
Print a single number T, which is the minimum time required to travel from (0,0) to the nth vertex. The answer is accepted if it has an absolute or relative error of at most 10^{-6}.
sample
2 10 5
10 0
20 0
2.000000
</p>