#P1193C. Scissors and Tape

    ID: 4351 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>*special problemconstructive algorithmsgeometry

Scissors and Tape

Description

You are given a piece of paper in the shape of a simple polygon SS. Your task is to turn it into a simple polygon TT that has the same area as SS.

You can use two tools: scissors and tape. Scissors can be used to cut any polygon into smaller polygonal pieces. Tape can be used to combine smaller pieces into larger polygons. You can use each tool multiple times, in any order.

The polygons given in the input have integer coordinates, but you are allowed to produce shapes with non-integer coordinates in your output.

A formal definition of the task follows.

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

  • The closed polyline Q0Q1Q2Qn1Q0Q_0Q_1Q_2\dots Q_{n-1}Q_0 never touches or intersects itself, and therefore it forms the boundary of a simple polygon.
  • The polyline goes around the boundary of the polygon in the counter-clockwise direction.

The polygon whose boundary is the shape QQ will be denoted P(Q)P(Q).

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

Note that mirroring a shape is not allowed. Also note that the order of points matters: the shape (Q1,,Qn1,Q0)(Q_1,\dots,Q_{n-1},Q_0) is not necessarily equivalent to the shape (Q0,,Qn1)(Q_0,\dots,Q_{n-1}).

In the figure on the left: Shapes UU and VV are equivalent. Shape WW is not equivalent with them because the points of WW are given in a different order. Regardless of the order of points, the fourth shape is not equivalent with the previous ones either as flipping a shape is not allowed.

In both input and output, a shape with nn points is represented as a single line that contains 2n+12n+1 space-separated numbers: the number nn followed by the coordinates of the points: Q0,xQ_{0,x}, Q0,yQ_{0,y}, Q1,xQ_{1,x}, ...

Shapes have identification numbers (IDs). The given shape SS has ID 0, the shapes you produce in your solutions are given IDs 1, 2, 3, ..., in the order in which they are produced.

Shapes B1,,BkB_1,\dots,B_k form a subdivision of shape AA if:

  • The union of all P(Bi)P(B_i) is exactly P(A)P(A).
  • For each iji\neq j, the area of the intersection of P(Bi)P(B_i) and P(Bj)P(B_j) is zero.

The scissors operation destroys one existing shape AA and produces one or more shapes B1,,BkB_1,\dots,B_k that form a subdivision of AA.

In the figure: Shape AA (square) subdivided into shapes B1B_1, B2B_2, B3B_3 (the three triangles). One valid way to describe one of the BiB_i is "3 3 1 6 1 5.1 4".

The tape operation destroys one or more existing shapes A1,,AkA_1,\dots,A_k and produces one new shape BB. In order to perform this operation, you must first specify shapes C1,,CkC_1,\dots,C_k and only then the final shape BB. These shapes must satisfy the following:

  • For each ii, the shape CiC_i is equivalent to the shape AiA_i.
  • The shapes C1,,CkC_1,\dots,C_k form a subdivision of the shape BB.

Informally, you choose the shape BB and show how to move each of the existing AiA_i to its correct location CiC_i within BB. Note that only the shape BB gets a new ID, the shapes CiC_i do not.

The first line contains the source shape SS.

The second line contains the target shape TT.

Each shape has between 3 and 10 points, inclusive. Both shapes are given in the format specified above.

All coordinates in the input are integers between 106-10^6 and 10610^6, inclusive.

In each shape, no three points form an angle smaller than 3 degrees. (This includes non-consecutive points and implies that no three points are collinear.)

The polygons P(S)P(S) and P(T)P(T) have the same area.

Whenever you use the scissors operation, output a block of lines of the form:


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

where id(A)id(A) is the ID of the shape you want to destroy, kk is the number of new shapes you want to produce, and B1,,BkB_1,\dots,B_k are those shapes.

Whenever you use the tape operation, output a block of lines of the form:


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

where kk is the number of shapes you want to tape together, id(A1),,id(Ak)id(A_1),\dots,id(A_k) are their IDs, C1,,CkC_1,\dots,C_k are equivalent shapes showing their position within BB, and BB is the final shape obtained by taping them together.

It is recommended to output coordinates of points to at least 10 decimal places.

The output must satisfy the following:

  • All coordinates of points in the output must be between 107-10^7 and 10710^7, inclusive.
  • Each shape in the output must have at most 100100 points.
  • In each operation the number kk of shapes must be between 11 and 100100, inclusive.
  • The number of operations must not exceed 20002000.
  • The total number of points in all shapes in the output must not exceed 2000020000.
  • In the end, there must be exactly one shape (that hasn't been destroyed), and that shape must be equivalent to TT.
  • All operations must be valid according to the checker. Solutions with small rounding errors will be accepted. (Internally, all comparisons check for absolute or relative error up to 10310^{-3} when verifying each condition.)

Scoring

A shape is called a nice rectangle if it has the form ((0,0), (x,0), (x,y), (0,y))((0,0),~ (x,0),~ (x,y),~ (0,y)) for some positive integers xx and yy.

A shape is called a nice square if additionally x=yx=y.

A shape AA is called strictly convex if all inner angles of the polygon P(A)P(A) are smaller than 180 degrees.

Subtask 1 (5 points): SS and TT are nice rectangles. All coordinates of all points are integers between 0 and 10, inclusive

Subtask 2 (13 points): SS is a nice rectangle with x>yx>y, and TT is a nice square

Subtask 3 (12 points): SS and TT are nice rectangles

Subtask 4 (14 points): SS is a triangle and TT is a nice square

Subtask 5 (10 points): SS and TT are triangles

Subtask 6 (16 points): SS is a strictly convex polygon and TT is a nice rectangle

Subtask 7 (11 points): TT is a nice rectangle

Subtask 8 (19 points): no additional constraints

Input

The first line contains the source shape SS.

The second line contains the target shape TT.

Each shape has between 3 and 10 points, inclusive. Both shapes are given in the format specified above.

All coordinates in the input are integers between 106-10^6 and 10610^6, inclusive.

In each shape, no three points form an angle smaller than 3 degrees. (This includes non-consecutive points and implies that no three points are collinear.)

The polygons P(S)P(S) and P(T)P(T) have the same area.

Output

Whenever you use the scissors operation, output a block of lines of the form:


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

where id(A)id(A) is the ID of the shape you want to destroy, kk is the number of new shapes you want to produce, and B1,,BkB_1,\dots,B_k are those shapes.

Whenever you use the tape operation, output a block of lines of the form:


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

where kk is the number of shapes you want to tape together, id(A1),,id(Ak)id(A_1),\dots,id(A_k) are their IDs, C1,,CkC_1,\dots,C_k are equivalent shapes showing their position within BB, and BB is the final shape obtained by taping them together.

It is recommended to output coordinates of points to at least 10 decimal places.

The output must satisfy the following:

  • All coordinates of points in the output must be between 107-10^7 and 10710^7, inclusive.
  • Each shape in the output must have at most 100100 points.
  • In each operation the number kk of shapes must be between 11 and 100100, inclusive.
  • The number of operations must not exceed 20002000.
  • The total number of points in all shapes in the output must not exceed 2000020000.
  • In the end, there must be exactly one shape (that hasn't been destroyed), and that shape must be equivalent to TT.
  • All operations must be valid according to the checker. Solutions with small rounding errors will be accepted. (Internally, all comparisons check for absolute or relative error up to 10310^{-3} when verifying each condition.)

Sample Input 1

6 0 0 6 0 6 4 5 4 5 9 0 9
4 0 0 7 0 7 7 0 7

Sample Output 1

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

Sample Input 2

4 0 0 3 0 3 3 0 3
4 7 -1 10 -1 11 2 8 2

Sample Output 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

Sample Input 3

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

Sample Output 3

scissors
0 2
4 1.470000000 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.470000000 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

Note

The figure below shows the first example output. On the left is the original figure after using the scissors, on the right are the corresponding CiC_i when we tape those pieces back together.

In the second example output, note that it is sufficient if the final shape is equivalent to the target one, they do not have to be identical.

The figure below shows three stages of the third example output. First, we cut the input rectangle into two smaller rectangles, then we cut the bigger of those two rectangles into two more. State after these cuts is shown in the top left part of the figure.

Continuing, we tape the two new rectangles together to form a six-sided polygon, and then we cut that polygon into three 2-by-1 rectangles and one smaller rectangle. This is shown in the bottom left part of the figure.

Finally, we take the rectangle we still have from the first step and the four new rectangles and we assemble them into the desired 3-by-3 square.