#P1995. Fastest Path in the Intelligent Car Race
Fastest Path in the Intelligent Car Race
Fastest Path in the Intelligent Car Race
The new edition of the Intelligent Car Competition has begun at JL University! The race track is composed of n rectangular zones placed side by side. The i-th rectangle has its bottom‐left and top‐right coordinates given by \( (x_{i,1}, y_{i,1}) \) and \( (x_{i,2}, y_{i,2}) \), respectively. It is guaranteed that \( x_{i,1} < x_{i,2} = x_{i+1,1} \) and \( y_{i,1} < y_{i,2} \), and that each pair of adjacent rectangles shares an overlapping edge (as shown by the dashed line in the figure), allowing the intelligent car to safely pass from one zone to the next.
Given a starting point \( S \) and an ending point \( T \), the driver needs to program the car to travel from \( S \) to \( T \) in the least possible time without leaving the track. The car moves at a constant speed \( v \) and turning does not consume any extra time. Your task is to calculate the minimum time required for the car to complete the race.
Note: Since the car can move in any direction, the travel time is equal to the Euclidean distance along the shortest path within the track divided by the speed \( v \). In other words, if the shortest path length is \( d \), then the answer is \( \frac{d}{v} \).
inputFormat
The input begins with two numbers n and v (\( 1 \leq n \leq 1000 \), \( v > 0 \)). The next line contains two floating-point numbers representing the coordinates of the start point \( S = (S_x, S_y) \). The following line contains two floating-point numbers representing the coordinates of the end point \( T = (T_x, T_y) \). Then follow n lines, each line containing four floating-point numbers: \( x_{i,1} \), \( y_{i,1} \), \( x_{i,2} \), \( y_{i,2} \), which represent a rectangle's bottom‐left and top‐right coordinates respectively.
outputFormat
Output a single floating-point number, which is the minimum time required for the car to travel from \( S \) to \( T \). The answer will be accepted if the absolute or relative error does not exceed \( 10^{-6} \).
sample
2 1
0 1
4 1
0 0 2 2
2 0 4 2
4.0000000000