#P6848. [CEOI 2019] Scissors and Tape

[CEOI 2019] Scissors and Tape

Description

You are given a simple polygon SS, and you want to transform it into a simple polygon TT with the same area.

You can use two tools: scissors and tape. Scissors can cut any polygon into smaller polygons. Tape can glue smaller polygons into a larger polygon. You may use each tool any number of times, in any order.

All polygon vertices in the input have integer coordinates, but your solution is allowed to create polygons whose vertex coordinates are not integers.

The formal definition of the task is as follows:

A shape Q=(Q0,Qn1)Q=(Q_0,\ldots Q_{n-1}) is a sequence of at least three points in the plane such that:

  • The closed polyline Q0,Q1,Q2,Qn1,Q0Q_0,Q_1,Q_2,\ldots Q_{n-1},Q_0 does not self-intersect.
  • This polyline goes counterclockwise around the boundary of the polygon.

The polygon with boundary given by shape QQ is denoted by P(Q)P(Q).

Two shapes are equivalent if and only if one can be translated or rotated to become identical to the other.

Reflection is not allowed, and the order of points matters: (Q0,Q1Qn1)(Q_0,Q_1\ldots Q_{n-1}) is not necessarily equivalent to (Q1Qn1,Q0)(Q_1\ldots Q_{n-1},Q_0).

In the figure above, shapes UU and VV are equivalent, but shape WW is not equivalent to them, because the order of the given points is different. In any case, the fourth shape is not identical to any of the first three, because reflection is not allowed.

Each shape is represented by 2×n+12\times n+1 numbers. The first number is nn, the number of points of the shape. Then follow 2×n2\times n numbers Q0,x,Q0,y,Q1,x,,Qn1,x,Qn1,yQ_{0,x},Q_{0,y},Q_{1,x},\ldots,Q_{n-1,x},Q_{n-1,y}. Each pair of numbers gives the coordinates of one point in the shape; for example, (Q0,x,Q0,y)(Q_{0,x},Q_{0,y}) is the coordinate of Q0Q_0.

Shapes B1,B2,BkB_1,B_2,\ldots B_k are called a partition of shape AA if and only if:

  • The union of all P(Bi)P(B_i) equals P(A)P(A).
  • For all iji\not=j, P(Bi)P(B_i) and P(Bj)P(B_j) do not intersect.

Shapes have IDs. The ID of SS is 00. The shapes you create in your solution will have IDs 1,2,3,1,2,3,\ldots.

Scissors cut an existing shape AA and produce a partition B1,B2,BkB_1,B_2,\ldots B_k of AA.

In the figure above, shape AA is partitioned into three triangles B1,B2,B3B_1,B_2,B_3. One way to describe the red triangle is 3 3 1 6 1 5.1 4.

Tape can glue existing shapes A1,AkA_1,\ldots A_k and turn them into a shape BB. To perform this operation, you must give C1,,CkC_1,\ldots,C_k and the final shape BB, and satisfy the following requirements:

  • CiC_i is equivalent to AiA_i.
  • C1,,CkC_1,\ldots,C_k form a partition of BB.

Informally, you choose the shape BB, and then show how to move each existing AiA_i to its correct position CiC_i to form BB. Note that shape BB must be assigned a new ID, but the CiC_i do not need IDs.

Input Format

The first line is the shape SS.

The second line is the shape TT.

Output Format

Each time you use scissors, output in the following format:

scissors
id(A) k
B_1
B_2
...
B_k

Each time you use tape, output in the following format:

tape
k id(A_1) ... id(A_k)
C_1
C_2
...
C_k
B

Your output must satisfy the following constraints:

  • All point coordinates in the output must be within [107,107][-10^7,10^7].
  • Each shape in the output may have at most 100100 points.
  • In each operation, 1k1001\le k\le 100.
  • The number of operations is at most 2×1032\times 10^3.
  • The total number of points across all shapes in the output does not exceed 2×1042\times 10^4.
  • In the end, there must be exactly one shape left, and it must be equivalent to TT.
6 0 0 6 0 6 4 5 4 5 9 0 9
4 0 0 7 0 7 7 0 7

scissors
0 5
3 0 0 3 0 3 4
3 3 4 0 4 0 0
3 3 0 6 0 6 4
3 6 4 3 4 3 0
4 0 4 5 4 5 9 0 9
tape
5 1 2 5 3 4
3 0 3 0 0 4 0
3 4 0 7 0 7 4
4 0 3 4 0 7 4 3 7
3 7 4 7 7 3 7
3 3 7 0 7 0 3
4 0 0 7 0 7 7 0 7
4 0 0 3 0 3 3 0 3
4 7 -1 10 -1 11 2 8 2

scissors
0 2
3 0 0 1 3 0 3
4 1 3 0 0 3 0 3 3
tape
2 1 2
3 110 -1 111 2 110 2
4 108 2 107 -1 110 -1 110 2
4 107 -1 110 -1 111 2 108 2

4 0 0 9 0 9 1 0 1
4 0 0 3 0 3 3 0 3

scissors
0 2
4 1.47000000000 0 9 0 9 1 1.470000000 1
4 0 0 1.470000000 0 1.470000000 1 0 1
scissors
1 2
4 1.470000000 0 6 0 6 1 1.470000000 1
4 9 0 9 1 6 1 6 0
tape
2 4 3
4 3 2 3 1 6 1 6 2
4 6 1 1.470000000 1 1.470000000 0 6 0
6 1.470000000 0 6 0 6 2 3 2 3 1 1.47 1
scissors
5 4
4 1.470000000 0 3 0 3 1 1.470000000 1
4 3 0 4 0 4 2 3 2
4 4 2 4 0 5 0 5 2
4 5 0 6 0 6 2 5 2
tape
5 2 6 7 8 9
4 0 0 1.470000000 0 1.470000000 1 0 1
4 1.470000000 0 3 0 3 1 1.470000000 1
4 0 2 0 1 2 1 2 2
4 0 2 2 2 2 3 0 3
4 3 3 2 3 2 1 3 1
4 0 0 3 0 3 3 0 3

Hint

Sample Explanation

Sample 1 Explanation

The top-left figure is the original shape after the scissors operation, and the right side shows the corresponding CiC_i after using tape.

Sample 2 Explanation

Note that the target polygon and the polygon you finally obtain only need to be equivalent; they do not need to be exactly the same.

Sample 3 Explanation

The following figure shows the three stages of the output for this sample:

Constraints

For 100%100\% of the testdata, it is guaranteed that the number of points of SS and TT is 10\le 10 and 3\ge 3. All input point coordinates are within [106,106][-10^6,10^6]. No three points are collinear. The areas of P(S)P(S) and P(T)P(T) are equal.

If a shape has vertices (0,0),(x,0),(0,y),(x,y)(0,0),(x,0),(0,y),(x,y) where x,yx,y are positive integers, then it is called a good rectangle.

If a shape is a good rectangle and x=yx=y, then it is called a good square.

If every interior angle of polygon P(A)P(A) is less than 180180 degrees, then shape AA is called a strictly convex polygon.

The detailed subtask constraints are as follows: | Subtask ID | Constraints | Score | | :-: | :-: | :-: | | 1 | SS and TT are good rectangles, and all input point coordinates are within [1,10][1,10] | 55 | | 2 | SS is a good rectangle and x>yx>y, TT is a good square | 1313 | | 3 | S,TS,T are good rectangles | 1212 | | 4 | SS is a triangle, TT is a good square | 1414 | | 5 | S,TS,T are triangles | 1010 | | 6 | SS is a strictly convex polygon, TT is a good rectangle | 1616 | | 7 | TT is a good rectangle | 1111 | | 8 | No special constraints | 1919 |

Notes

This problem is translated from Central-European Olympiad in Informatics 2019 Day 2 T3 Scissors and Tape

Translated by ChatGPT 5