#P8610. Bicycle Axle Path Length
Bicycle Axle Path Length
Bicycle Axle Path Length
Due to long‐term wear, a tree‐lined road has become uneven. Dongdong rides his bicycle along this road. Although the ride is bumpy, he takes pleasure in it. The road is modeled as a sequence of connected line segments on a plane, with the coordinates of all endpoints given. The front wheel of his bicycle (of radius ) always rolls without slipping along the road. However, when the road changes direction at a vertex, the wheel’s axle (the center of the front wheel) does not follow the exact road polyline – instead, it rounds the corner along a circular arc. In particular, at a turning point the following adjustments occur:
For a vertex that is a local extremum in the vertical () coordinate (i.e. a turning point), let the two adjacent segments have vectors (\vec{v}) and (\vec{w}). Let the turning angle (in radians) be [ \varphi=\arccos\Bigl(\frac{\vec{v}\cdot\vec{w}}{|\vec{v}|,|\vec{w}|}\Bigr), ] and define [ d=R\tan\Bigl(\frac{\varphi}{2}\Bigr). ] Then the axle’s travel on the two segments adjoining the vertex is shortened by (d) (each) and replaced by a circular arc of length (R\varphi).
Thus, if the road consists of segments with lengths (L_1, L_2, \ldots, L_m) (with (m=n-1) where (n) is the number of points) and if the vertex at index (i) (with (1\le i\le n-2)) is a turning point (i.e. a local maximum or minimum in the (y) coordinate), then it contributes a correction of [ -2R\tan\Bigl(\frac{\varphi}{2}\Bigr)+R\varphi ] to the total axle path length. (If a vertex is not a turning point, no correction is applied.)
The final axle path length is computed as [ \text{total} = \sum_{i=1}^{m} L_i + \sum_{\text{turning vertices}} \Bigl(-2R\tan\Bigl(\frac{\varphi}{2}\Bigr)+R\varphi\Bigr). ]
Your task is: given the radius (R) of the wheel and the coordinates of the road, compute the total length of the path traveled by the front wheel’s axle. The answer should be printed to 4 decimal places.
Note: In our model, a vertex is considered a turning point if its (y) coordinate is either strictly greater than both its neighbors or strictly less than both neighbors.
Input Format: The first line contains two numbers: an integer \(n\) (the number of measured points, with \(n\ge2\)) and a floating‐point number \(R\) (the radius of the front wheel). The following \(n\) lines each contain two real numbers \(x\) and \(y\), representing the coordinates of the road in order.
Output Format: Output a single number: the total length of the axle’s path, accurate to 4 decimal places.
Example Explanation: For example, if the input is
4 1.50 0 0 2 0 4 -1 6 -1
then the road segments have lengths (L_1=2.0000,; L_2\approx2.2361,; L_3=2.0000). Only the vertex at point (4, -1) is a turning point (since it is a local minimum with respect to (y): 0 > -1 < -1 is considered turning in our model). For that turning vertex the angle is approximately (\varphi\approx0.4636) and (d=1.50\tan(0.2318)\approx0.3541). Thus the axle travels
- along the first segment: full length 2.0000,
- along the second segment: shortened by (d) (i.e. (2.2361-0.3541=1.8820)),
- along the third segment: shortened by (d) (i.e. (2.0000-0.3541=1.6459)),
- and a circular arc of length (1.50\times0.4636\approx0.6955) replaces the two cut portions.
The total length is (2.0000+1.8820+1.6459+0.6955=6.2234) (approximately).
Be sure your program works for any valid input.
inputFormat
The first line contains an integer n
(\(n \ge 2\)) and a floating–point number R
(the wheel radius). Each of the next n
lines contains two real numbers denoting the coordinates x
and y
of a point on the road, given in order.
outputFormat
Output a single number: the total length of the axle’s path, printed to 4 decimal places.
sample
4 1.50
0 0
2 0
4 -1
6 -1
6.2234