#P8610. [蓝桥杯 2013 国 A] 车轮轴迹

[蓝桥杯 2013 国 A] 车轮轴迹

Problem Description

Dongdong rides his bicycle home every day along a long and narrow tree-lined path. Because the road has been poorly maintained for many years, it has become very uneven. Although Dongdong bumps a lot each time, he still treats riding through the path as a kind of fun.

Because of the bumps, the route Dongdong takes home is a curve that goes up and down. Dongdong wants to know: how long is this curve exactly? More precisely, Dongdong wants to know the length of the path traveled by the axle (the center of the circle) of his bicycle’s front wheel from the start of the path to the end of the path.

Dongdong measured the road surface. He simplified the road into straight line segments of different lengths. These segments are connected end to end and lie in the same plane. He also built a Cartesian coordinate system in this plane and computed the coordinates of all segment endpoints.

Assume that during the ride, the front wheel always moves forward while staying in contact with the road surface.

Figure 11 shows a simple example of a road surface, where the blue solid line is the road surface and the red dashed line is the path traveled by the wheel axle. In this example, the front wheel axle starts from point AA, moves horizontally to point BB, then goes around point FF on the ground to point CC (forming a circular arc), then goes downhill along a straight line to point DD, and finally moves horizontally to point EE. In this figure, the ground coordinates in order are: (0,0),(2,0),(4,1),(6,1)(0,0),(2,0),(4,-1),(6,-1). The front wheel radius is 1.501.50. The distances traveled by the front wheel axle are:

AB=2.0000AB=2.0000; arc length BC=0.6955BC=0.6955; CD=1.8820CD=1.8820; DE=1.6459DE=1.6459.

The total length is 6.22336.2233.

Figure 22 shows a more complex example of a road surface. In this example, the wheel starts going uphill (at point DD) before finishing the first downhill. Then at the peak of the slope, it needs to go around a larger circular arc from EE to FF. In this figure, the front wheel radius is 11. The length of each part is:

AB=3.0000AB=3.0000; arc length BC=0.9828BC=0.9828; CD=1.1913CD=1.1913; DE=2.6848DE=2.6848; arc length EF=2.6224EF=2.6224; FG=2.4415FG=2.4415; GH=2.2792GH=2.2792.

The total length is 15.202115.2021.

Now you are given the wheel radius and the description of the road surface. Please compute the total length of the wheel axle trajectory.

Input Format

The first line contains an integer nn and a real number rr, separated by a space, representing the number of coordinate points describing the road surface and the radius of the wheel.

The next nn lines each contain two real numbers. In the ii-th line, the two real numbers xi,yix_i,y_i represent the coordinates of the ii-th point describing the road surface.

The road surface is defined as the polyline formed by connecting all the given road surface points in order. The given road surface always satisfies the following properties:

  • The first coordinate point is always (0,0)(0,0).
  • The yy-coordinates of the first point and the second point are the same.
  • The yy-coordinates of the last point and the second-to-last point are the same.
  • The distance between the first point and the second point is at least the wheel radius.
  • The distance between the last point and the second-to-last point is at least the wheel radius.
  • The xx-coordinate of each subsequent point is greater than that of the previous point, i.e., for all ii, xi+1>xix_{i+1}>x_i.

Output Format

Output a real number, rounded to two decimal places, representing the total length traveled by the wheel axle.

Your result must be exactly the same as the reference answer to get points. The testdata guarantees that the third digit after the decimal point of the exact value is not 44 or 55.

4 1.50
0.00 0.00
2.00 0.00
4.00 -1.00
6.00 -1.00
6.22
6 1.00
0.00 0.00
3.00 0.00
5.00 -3.00
6.00 2.00
7.00 -1.00
10.00 -1.00
15.20

Hint

For 20%20\% of the testdata, n=4n=4.

For 40%40\% of the testdata, n10n \le 10.

For 100%100\% of the testdata, 4n1004 \le n \le 100, 0.5r20.00.5 \le r \le 20.0, xi2000.0x_i \le 2000.0, 2000.0yi2000.0-2000.0 \le y_i \le 2000.0.

Time limit: 1 second, 64 MB. Lanqiao Cup 2013, the 4th National Finals.

Translated by ChatGPT 5