P29053 [洛谷] [CTSC2005] The Lonely Shepherdess
入门
题目描述

Problem Description

In the Dalarna region of Sweden, there is a high mountain. On the mountain, there is a small hut where a shepherdess lives. Every morning, a melodious flute sound comes from the neighboring mountaintop, and the shepherdess responds with her own song while standing in the hut.

The overhead view of the hut is a simple polygon with \( n \) vertices. Each wall can reflect sound, but due to unavoidable energy loss, it can only reflect up to \( k \) times (\( k = 0 \) means the sound cannot be reflected). The walls are very smooth, so the reflection follows the law where the angle of reflection equals the angle of incidence, as shown in Figure 1. Corners of the walls cannot reflect sound, but other parts of the walls—even those close to the corners—can reflect sound.

One day, the shepherdess wondered: in which parts of the hut can her song be heard? Assuming all listeners sit against the walls inside the hut, how long is the total length of the walls where the song can reach? Figure 2 shows four schematic diagrams representing the initial situation and the areas reached by the sound after 0, 1, and 2 reflections. The gray parts indicate the areas where the song can be heard, and the black dot represents the shepherdess's position. The problem asks for the total length of the polygon boundary where the gray parts are located.

Input Format

The first line contains four integers \( n \), \( k \), \( x \), \( y \), representing the number of wall corners of the hut, the maximum number of reflections, and the coordinates of the shepherdess (the shepherdess's position is guaranteed to be inside the hut and at least 1 unit away from the walls). The following \( n \) lines each contain two integers \( x \), \( y \), representing the coordinates of the \( i \)-th wall corner. The corners are listed in clockwise or counterclockwise order.

Output Format

The output file contains only one real number \( L \), representing the total length of the walls where the song can be heard. The result should be rounded to two decimal places.

Sample Input and Output

Input Sample #1

5 0 100 135
20 200
200 100
300 125
40 10
100 100

Output Sample #1

469.86

Input Sample #2

8 1 25 15
0 0
0 20
30 20
30 0
20 0
20 10
10 10
10 0

Output Sample #2

106.67

Notes

Scoring Method

If the absolute difference between the contestant's output and the reference output is no more than \( 0.02 \), the test case is awarded full points. If the difference exceeds \( 0.02 \) but does not exceed \( 1 \), the test case is awarded \( 50\% \) of the points. In Sample 1, answers of \( 469.84 \) and \( 469.88 \) both receive full points, while \( 468.86 \) and \( 470.86 \) both receive \( 50\% \) of the points.

Constraints

\( 3 \leq n \leq 50 \), \( 0 \leq k \leq 5 \), all coordinates are integers with absolute values not exceeding \( 1000 \).

\( 50\% \) of the data satisfies \( k \leq 1 \).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 0 100 135 20 200 200 100 300 125 40 10 100 100
样例输出
469.86