#P15490. [IOI 2004] Polygon

[IOI 2004] Polygon

Description

A polygon consists of all points on or enclosed by its border. A convex polygon has the property that for any two points XX and YY of the polygon, the line segment connecting XX and YY is inside the polygon. All polygons in this task are convex polygons with at least two vertices, and all vertices in a polygon are different and have integer coordinates. No three vertices of the polygon are collinear. The word “polygon” below always refers to such polygons.

Given two polygons AA and BB, the Minkowski sum of AA and BB consists of all the points of the form (x1+x2,y1+y2)(x1+x2, y1+y2) where (x1,y1)(x1, y1) is a point in AA and (x2,y2)(x2, y2) is a point in BB. It turns out that the Minkowski sum of polygons is also a polygon. The figure below shows an example: two triangles and their Minkowski sum.

We study a reverse operation to the Minkowski sum. For a given polygon PP, we are looking for two polygons AA and BB such that:

  • PP is the Minkowski sum of AA and BB,
  • AA has from 22 to 44 different vertices, i.e. it is a segment (22 vertices), a triangle (33 vertices) or a quadrilateral (44 vertices),
  • AA should have as many vertices, as possible, i.e.:
    • AA should be a quadrilateral, if possible,
    • if AA cannot be a quadrilateral, it should be a triangle, if possible,
    • otherwise it should be a segment.

Clearly, neither AA nor BB can be equal to PP because then the other summand would have to be a point, which is not a valid polygon.

You are given a set of input files, each containing a description of a polygon PP. For each input file you should find the polygons AA and BB, as required above, and create an output file containing descriptions of AA and BB. For the given input files such polygons AA and BB can always be found. If there are many correct results, you should find and output one of them. You should not submit any programs, just the output files.

Input Format

You are given 1010 problem instances in the text files named polygon1.in to polygon10.in, where the number after polygon is the input number. Each input file is organized as follows. The first line contains one integer NN: the number of vertices of the polygon PP. The following NN lines describe the vertices in a counter-clockwise order, one vertex per line. Line I+1I+1 (for I=1,2,,NI = 1, 2, \ldots, N) contains two integers XIX_I and YIY_I, separated by a space: coordinates of the IIth vertex of the polygon. All input coordinates are non-negative integers.

Output Format

You are to submit 1010 output files corresponding to the given input files which describe the required polygons AA and BB.

The output format is similar to the input format. The second line is to contain one integer NAN_A: the number of vertices in A(2NA4)A (2\le N_A\le4). The following NAN_A lines describe the vertices of AA in the counter-clockwise order, one vertex per line. Line I+2I+2 (for I=1,2,,NAI = 1, 2, \ldots, N_A) contains two integers XX and YY, separated by a space: coordinates of the IIth vertex of the polygon AA. Line NA+3NA+3 should contain one integer NBN_B: the number of vertices in BB,(2NB)(2\le NB). The following NBN_B lines describe the vertices of BB in the counter-clockwise order, one vertex per line. Line NA+J+3N_A+J+3 (for J=1,2,,NBJ = 1, 2, \ldots, N_B) contains two integers XX and YY, separated by a space: coordinates of the JJth vertex of the polygon BB.

5
0 1
0 0
2 0
2 1
1 2 
3
0 0
2 0
1 1
2
0 1
0 0 

或

3
0 0
1 0
1 1
3
0 1
0 0
1 0