eolymp
bolt
Try our new interface for solving problems
Problems

Psychic Accelerator

Psychic Accelerator

In the west of Tokyo, there is a city named "Academy City." There are many schools and laboratories to develop psychics in Academy City. You are a psychic student of a school in Academy City. Your psychic ability is to give acceleration to a certain object. You can use your psychic ability anytime and anywhere, but there are constraints. If the object remains stationary, you can give acceleration to the object in any direction. If the object is moving, you can give acceleration to the object only in 1) the direction the object is moving to, 2) the direction opposite to it, or 3) the direction perpendicular to it. Today’s training menu is to move the object along a given course. For simplicity you can regard the course as consisting of line segments and circular arcs in a 2-dimensional space. The course has no branching. All segments and arcs are connected smoothly, i.e. there are no sharp corners. In the beginning, the object is placed at the starting point of the first line segment. You have to move the object to the ending point of the last line segment along the course and stop the object at that point by controlling its acceleration properly. Before the training, a coach ordered you to simulate the minimum time to move the object from the starting point to the ending point. Your task is to write a program which reads the shape of the course and the maximum acceleration amax you can give to the object and calculates the minimum time to move the object from the starting point to the ending point. The object follows basic physical laws. When the object is moving straight in some direction, with acceleration either forward or backward, the following equations hold: \textbf{v = v_0 + at} and \textbf{s = v_0t +1/2at^2} where \textbf{v}, \textbf{s}, \textbf{v_0}, \textbf{a}, and \textbf{t} are the velocity, the distance from the starting point, the initial velocity (i.e. the velocity at the starting point), the acceleration, and the time the object has been moving in that direction, respectively. Note that they can be simplified as follows: \textbf{v^2 - v^2_0= 2as} When the object is moving along an arc, with acceleration to the centroid, the following equations hold: \textbf{a =v^2/r} wher \textbf{v}, \textbf{a}, and \textbf{r} are the velocity, the acceleration, and the radius of the arc, respectively. Note that the object cannot change the velocity due to the criteria on your psychic ability. \InputFile The input has the following format: \textbf{N a_maxx_\{a,1\} y_\{a,1\} x_\{b,1\} y_\{b,1\}x_\{a,2\} y_\{a,2\} x_\{b,2\} y_\{b,2\}...} \textbf{N} is the number of line segments; \textbf{a_max} is the maximum acceleration you can give to the object; (\textbf{x_\{a,i\}}, \textbf{y_\{a,i\}}) and (\textbf{x_\{b,i\}}, \textbf{y_\{b,i\}}) are the starting point and the ending point of the \textbf{i}-th line segment, respectively. The given course may have crosses but you cannot change the direction there. The input meets the following constraints: \textbf{0} < \textbf{N} ≤ \textbf{40000}, \textbf{1} ≤ \textbf{a_max} ≤ \textbf{100}, and \textbf{-100} ≤ \textbf{x_ai}, \textbf{y_ai}, \textbf{x_bi}, \textbf{y_bi} ≤ \textbf{100}. \OutputFile Print the minimum time to move the object from the starting point to the ending point with an relative or absolute error of at most \textbf{10^\{-6\}}. You may output any number of digits after the decimal point.
Time limit 8 seconds
Memory limit 32 MiB
Input example #1
2 1
0 0 1 0
1 1 0 1
Output example #1
5.279363861705668
Source ACM-ICPC Japan Alumni Group Summer Camp 2010, Day 4, Tokyo, Japan, 2010-09-20