Triangle Puzzle
Time limit1sMemory limit512 MB
Count the sets of four triangles that can be rotated and moved, but not reflected, to form one large triangle with a piece at each corner and one in the center.
- Level
Medium7 of 10
- Topics
- Geometry, Brute force, Implementation
- Solved
- No attempts yet
Statement
The puzzle consists of triangles. To solve it, choose four of them and assemble a large triangle using the scheme below.
The triangles must not overlap, and together they must form one triangle. Exactly one of the chosen triangles sits at each of the three corners, and one triangle sits in the center. The triangles lie on a table. You may rotate and move them freely, but you may not reflect them. Find all distinct sets of four triangles from which the large triangle can be built this way. Two sets are different if some triangle belongs to one set but not to the other.
Input
The first line contains a single integer , the test number. The second line contains , the number of triangles in the puzzle (). Each of the next lines describes one triangle by the coordinates of its three corners, listed counterclockwise. All coordinates are integers with absolute value at most . No triangle is degenerate. In the initial layout, the triangles may overlap.
Output
On the first line, print the number of sets of four triangles from which the large triangle can be built. Then print the sets, one per line, as the numbers of their triangles. Triangles within a set may be printed in any order, and the sets may be printed in any order.
Hints
In the first example, the four given triangles form one large triangle, and no triangle needs to be rotated. In the second example, all triangles are the same right triangle whose two legs have length . Any four of them form the large triangle.