IOI '04 P3 - Polygon

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 2.0s
Memory limit: 1G

Problem type

A polygon consists of all points on or enclosed by its border. A convex polygon has the property that for any two points X and Y of the polygon, the line segment connecting X and Y 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 a polygon are collinear. The word "polygon" below always refers to such polygons.

Given two polygons A and B, the Minkowski sum of A and B consists of all the points of the form (x_1+x_2, y_1+y_2) where (x_1, y_1) is a point in A and (x_2, y_2) is a point in B. 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 P, we are looking for two polygons A and B such that:

  • P is the Minkowski sum of A and B,
  • A has from 2 to 4 different vertices, i.e. it is a segment (2 vertices), a triangle (3 vertices) or a quadrilateral (4 vertices),
  • A should have as many vertices, as possible, i.e.:
    • A should be a quadrilateral, if possible,
    • if A cannot be a quadrilateral, it should be a triangle, if possible,
    • otherwise it should be a segment.

Clearly, neither A nor B can be equal to P 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 P. For each input file you should find the polygons A and B, as required above, and create an output file containing descriptions of A and B. For the given input files, such polygons A and B can always be found. If there are many correct results, you should find and output one of them.

Input Specification

The first line contains one integer T (0 \le T \le 10), the index of the test case. T = 0 indicates that this is a sample test case.

The second line contains one integer N, the number of vertices of the polygon P.

The following N lines each contain two integers X_i, Y_i, the coordinates of the i-th vertex of the polygon. The vertices are given in counter-clockwise order. All input coordinates are non-negative integers.

Since this is intended to be an output-only problem, when you submit, you can submit a program that only prints the answer based on the test case number in the first line, and run your program locally to get the answer for each test case.

You can view the input files at polygon.zip.

Output Specification

In the first line, output an integer N_A (2 \le N_A \le 4), the number of vertices in polygon A.

In the following N_A lines, output two integers X, Y (-10^8 \le X, Y \le 10^8), representing the coordinates of a vertex of polygon A. The vertices should be given in counter-clockwise order.

In the next line, output an integer N_B (2 \le N_B \le 2\,000), the number of vertices in polygon B.

In the following N_B lines, output two integers X, Y (-10^8 \le X, Y \le 10^8), representing the coordinates of a vertex of polygon B. The vertices should be given in counter-clockwise order.

Sample Input

5
0 1
0 0
2 0
2 1
1 2

Sample Output 1

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

Sample Output 2

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

Explanation for Sample

For the sample input, either of the two outputs above are correct since in both cases A is a triangle and it cannot be a quadrilateral.


Comments

There are no comments at the moment.