LaLa and Magic Circle (LaLa Version)
Time limit2sMemory limit1024 MB
Repeatedly reflect non-convex chains of a simple polygon until it is convex, then print its vertices counterclockwise from the lexicographically smallest one.
- Level
Hard9 of 10
- Topics
- Geometry, Implementation
- Solved
- No attempts yet
Problem
has a pile of circles in her laboratory.
A circle can be represented as a simple polygon drawn with special ink, and is usable if and only if it is convex. i.e. all of its internal angles are equal or less than .
plans to turn every circle into a usable one. However, it may lose all its al power if done incorrectly. Thankfully, has the perfect al tool for that.
The tool works as follows. When you toss in a circle, if it's usable, it reports that it is. Otherwise, it takes two distinct points and such that
- and lie on the boundary of the convex hull of the circle, and
- none of the points on the path from to through the boundary of the circle in counterclockwise order lie on the boundary of the convex hull of the circle, except for and .
And then it rotates the - path by around the midpoint of and . In other words, for each point on the - path, becomes where the addition is done coordinate-wise over the two dimensional coordinate system over the paper the circle is drawn on. Note that the result of this modification is also a simple polygon.
got annoyed by how long it takes to convert them. In order to finish and take a nap as soon as possible, made the following observations.
- A circle always turns into a usable one within a finite number of applications of the tool.
- The set of points on the final circle is independent of the intermediate modifications. In other words, the shape and location of the final circle is a function of the initial circle.
Therefore, doesn't have to manually turn circles into usable ones with the tool. Instead, will compute the usable circle that can be made from the initial circle by a sequence of modifications by the tool and modify it in one go.
Write a program to help compute the final circle so that she can go take a nap.
Input
The input is given in the following format:
where the initial circle is the union of line segments connecting points and for all integers .
The input satisfies the following constraints:
- All numbers in the input are integers.
- and for all integers .
- or for all integers .
- The input defines a counterclockwise traversal of the boundary of a simple polygon. In particular, it does not intersect with itself.
Output
The output should be in the following format:
where the final usable circle is the union of line segments connecting points and for all integers .
The output should satisfy the following constraints:
- All the numbers in the output are integers.
- The point is lexicographically smaller than the point for all integers . i.e. () or ( and ).
- Points , , and are not collinear for all integers .
- The output defines a counterclockwise traversal of the boundary of a convex polygon.
It can be proved that the output satisfying the above constraints is unique.
Hint
The following illustrates the initial circle for the first sample.

The following illustrates the sequence of usage of the tool to make it usable. The dotted part of the boundary is the path modified by the tool, which becomes the red part after the modification.




