Under construction

Still being built. Things may change

Cut the Cake!

Interview

Time limit1sMemory limit1024 MB

Summary
Given a convex polygon and a horizontal cut y=Y, find the perimeters of the two pieces, smaller value first.
Level

Medium4 of 10

Topics
Geometry, Implementation
Solved
No attempts yet

Problem

On the faraway planet of Gastronomia, the native Gastronomes consider polygonal pancakes to be the highest form of art (as well as the tastiest). Every year, they celebrate the Polycake Festival, in which thousands of ninja chef monasteries perform the Thousand Slices, a series of rituals of tremendous importance to Gastronome society. In each of these rituals, a polycake is carefully placed on a ceremonial altar, and a ninja chef solemnly cuts the cake with a single, perfectly straight slice, dividing it into two pieces, one on the North part of the altar (representing the past) and the other on the South part (representing the future). The two pieces are carefully separated, and their perimeters are measured. The results determine the proportions of the ingredients used in polycakes planetwide, until the next Polycake Festival.

As the foremost Novice at the Temple of the Promised Cosmic Polycake, you are entrusted with the task of measuring the perimeters of the two slices. Take care, for any mistakes will be mercilessly mocked by the Brotherhood of the Illusory Polycake. It would be best if you wrote a program to do this.

Given a polygon representing the polycake in the Cartesian plane and a line parallel to the X-axis indicating the position of the slice, compute the perimeter of each of the two pieces thus formed. The perimeter of a polygon is the sum of the lengths of all its sides. The input polygons are convex and simple.

Input

The first input line contains a positive integer, nn, the number of polycakes used in the ritual. This is followed by nn data sets, each representing a single slicing of a polycake.

The first line of each set has two integers, VV (3≤V≤103 \le V \le 10) and YY (−1000≤Y≤1000-1000 \le Y \le 1000), the number of vertices in the polycake and the y-coordinate of the horizontal cut. The equation of a line parallel to the X-axis has the form y=ky=k.

The next VV lines each contain two integers, xx and yy (−1000≤x,y≤1000-1000 \le x, y \le 1000), the Cartesian coordinates of the vertices of the polycake, in counter-clockwise order.

The cut always goes through the cake and never passes through a vertex.

Output

For each test case, first output "Case #i:" where ii is the test case number, starting with 1. Then output "aa bb", the perimeters of the two slices, in increasing order. Output the results to 3 decimal places, rounded to the nearest thousandth (for example, 77.0113 rounds to 77.011, 88.0115 rounds to 88.012, and 99.0117 rounds to 99.012). Leave a blank line after the output for each test case. Follow the format illustrated in the sample output.

Examples1

  1. Example 1

    Input
    2
    4 2
    0 0
    4 0
    4 4
    0 4
    6 10
    3 15
    10 1
    12 5
    11 19
    9 23
    6 20
    
    Expected output
    Case #1: 12.000 12.000
    
    Case #2: 25.690 35.302