Problem F
Cutting a polygon
Given is a simple but not necessarily convex polygon. Given is also a line in the plane. If the polygon is cut along the line then we may get several smaller polygons. Your task is to find the length of the cut, that is the total length of the segments in the intersection of the line and the polygon.

Figure 1 illustrates the first cutting line for the polygon from the sample.
Input
Input consists of a number of cases. The data of each case
appears on a number of input lines, the first of which contains
two non negative integers
Input is terminated by a line with
Output
For each cutting line, print the total length of the segments in the intersection of the line and the polygon defined for this test case, with 3 digits after the decimal point. Note: the perimeter of a polygon belongs the polygon.
Sample Input 1 | Sample Output 1 |
---|---|
9 5 0 0 0 2 1 1 2 2 3 1 4 2 5 1 6 2 6 0 -1 2 7.5 1 0 1 6 1 0 1.5 6 1.5 0 2 6 1 0 0 0 2 0 0 |
2.798 6.000 3.000 2.954 2.000 |