Under construction

Still being built. Things may change

Cut It Out!

Time limit1sMemory limit128 MB

Summary
Given n triangular holes and 2n smaller triangles produced by splitting each hole along a cevian, match the two pieces to each hole using side lengths and angles.
Level

Medium7 of 10

Topics
Geometry, Hash map, Sorting, Implementation
Solved
No attempts yet

Problem

Tommy cut several triangular holes out of sheets of paper, leaving each sheet with one triangular hole. He then divided each of the triangles he had cut out into two triangles with a single straight cut starting from one corner. That is, for each original triangle he cut straight from one of its three vertices to a point on the opposite side, splitting it into two pieces.

The resulting triangular pieces then got randomly scattered. Write a program that determines which two pieces fill each triangular hole — that is, which pieces go into which hole.

Input

Each test case starts with an integer n≤20n \le 20, the number of holes that were cut out. It is followed by the coordinates of the holes, one hole per line; the holes are assumed to be numbered 1,2,…,n1, 2, \dots, n. After this come the coordinates of the 2n2n triangles resulting from the bisections, one triangle per line. These triangles are assumed to be numbered 1,2,…,2n1, 2, \dots, 2n and are listed in no particular order.

The specification of any hole or triangle has the form x1 y1 x2 y2 x3 y3x_1\ y_1\ x_2\ y_2\ x_3\ y_3, where each xix_i and yiy_i is given to the nearest thousandth and ∣xi∣,∣yi∣≤200|x_i|, |y_i| \le 200. No two holes are congruent and no two triangles are congruent. A value of n=0n = 0 terminates the input.

Output

For each test case, output the case number and then nn lines as follows:

Hole 1: t1a, t1b
Hole 2: t2a, t2b
...
Hole n: tna, tnb

where t1a,t1bt1a, t1b are the two triangles that fill hole 1, t2a,t2bt2a, t2b are the two triangles that fill hole 2, and so on. Always print the lower of the two numbers first on each line. Triangles must not be flipped over when filling a hole (only rotation and translation are allowed). Each test case has a unique solution. Separate the output for each test case with a blank line.

Note: when processing the triangles and checking equality of lengths, angles, or trigonometric values, you may assume two items are equal if they differ by less than 0.010.01.

Examples1

  1. Example 1

    Input
    1
    18.691 6.103 21.668 13.709 21.332 25.894
    59.388 30.873 55.299 36.186 61.45 22.97
    67.828 85.496 60.751 72.752 59.2 67.49
    3
    18.73 4.012 6.662 7.557 14.035 7.478
    14.869 32.398 32.341 31.772 7.522 29.674
    25.272 6.868 4.572 2.014 10.487 16.121
    26.135 53.073 44.18 50.723 40.31 42.91
    86.601 29.95 70.542 17.088 66.77 14.88
    90.344 89.528 92.179 88.665 87.99 82.54
    39.327 62.11 35.033 57.127 18.14 63.89
    37.13 80.202 36.308 75.111 34.28 75.11
    14.043 68.482 15.22 55.423 10.42 75.43
    0
    
    Expected output
    Case 1:
    Hole 1: 1, 2
    
    Case 2:
    Hole 1: 3, 5
    Hole 2: 2, 6
    Hole 3: 1, 4