#P5792. Shepherdess's Echo

    ID: 19020 Type: Default 1000ms 256MiB

Shepherdess's Echo

Shepherdess's Echo

A shepherdess lives in a mountain cabin in Dalarna, Sweden. The cabin’s floor plan is given as a simple polygon with \(n\) vertices. Each wall of the cabin can reflect sound following the law of reflection (i.e. the angle of incidence equals the angle of reflection) but with an energy loss that limits the number of reflections to at most \(k\) (with \(k=0\) meaning that no reflection is allowed). Every part of a wall (except the corners) can serve as a reflection point.

Every morning the sound of a flute from a neighboring mountain reaches the cabin. In response, the shepherdess sings from inside. If we assume that all the listeners are seated right next to the walls, she wonders: what is the total length of the wall segments in the cabin that can be reached by her song?

The four figures in Figure 2 show, respectively, the original condition and the regions reached by the sound after \(0\), \(1\), and \(2\) reflections. The gray parts indicate the portions of the walls that can be reached. In this problem your task is to compute the total length of the wall segments (i.e. the perimeter parts of the polygon) on which the sound can arrive.

Important Assumption: For the purpose of this problem, you may assume that the given polygon is convex. In a convex polygon every point on the boundary is directly reachable from any interior point. Hence, regardless of the value of \(k\), the song will eventually reach the entire boundary.

The answer should be output with a precision such that an absolute or relative error of at most \(10^{-6}\) is allowed.

inputFormat

The first line contains two integers \(n\) and \(k\) (with \(3 \le n \le 10^5\) and \(0 \le k \le 10\)), where \(n\) is the number of vertices of the polygon and \(k\) is the maximum number of reflections allowed.

The second line contains two real numbers \(x\) and \(y\) representing the coordinates of the shepherdess’s position inside the polygon.

The following \(n\) lines each contain two real numbers giving the coordinates of the vertices of the polygon in counterclockwise order.

outputFormat

Output a single real number — the total length of the wall segments that can be reached by the sound. Your answer is accepted if its absolute or relative error does not exceed \(10^{-6}\).

sample

4 0
0 0
0 0
4 0
4 3
0 3
14.000000

</p>