Irvanistan and Jikjikestan are two neighboring countries that have fought several wars with many casualties over their
border dispute. Despite the loss of lives in the scale of tens of thousands, none of their border claims have been accepted by the other party.
Recently, the logical leaders who have gained control of both countries have accepted the United Nations proposal to resolve their border dispute. The proposal is to come up with a shorter and simplified version of the border that is
calculated by a fair computer program.
To describe the problem accurately, let the current border P be a set of non-crossing line segments each connecting two border points. Let p1, p2, ..., pN be these border points; i.e., P is exactly composed of the line segments connecting pi and pi+1, for 1 <= i < N.
The UN suggests to create a new border C with points c1, c2, ..., cK, in such a way that c1 = p1 and cK = pN and the
following constraints are satisfied.
Your task is to find a new border C with the shortest possible length, while adhering to the above constraints.
There are multiple test cases in the input. The first line of each test case contains N(2 <= N <=500), the number of points followed by D(0 <= D <=500). Each of the next N lines contains two integers xi, yi (-10000 <= xi, yi <= 10000) which are the coordinates of the point pi. Note that the point coordinates are increasing; i.e. xi < xi+1 and yi < yi+1. The input terminates with a line containing two zeros.
For each test case write a single line containing the shortest possible length of the new border with exactly two digits after the decimal point.
4 3 1 1 2 2 4 5 6 6 3 0 1 1 5 4 8 8 0 0
7.07 10.00
Migrated from old NTUJ.
2009Tehran
No. | Testdata Range | Score |
---|