Problem Statement | |||||||||||||
| A "Polyline" is a continuous line composed of one or more line segments. In a rectangle defined by four points (0,0), (a, 0), (a, b), and (0, b), we can draw a polyline starting from the point (x0, y0) to the end point (x1, y1) with at least one intersection point with each of the four edges of the rectangle. Write a class Polyline with a method length that returns the shortest length of such a polyline. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | The polyline must not exceed the boundaries of the given rectangle. | ||||||||||||
| - | The starting point and ending point may overlap. | ||||||||||||
| - | Your return value must have an absolute or relative error less than 1e-9. | ||||||||||||
Constraints | |||||||||||||
| - | a and b will be between 2 and 200 inclusive. | ||||||||||||
| - | x0 and x1 will be between 1 and (a-1) inclusive. | ||||||||||||
| - | y0 and y1 will be between 1 and (b-1) inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||