Bisecting the Island
Time limit1sMemory limit256 MB
Split an axis-parallel simple polygon into two congruent pieces with one axis-parallel cut on integer coordinates, or report that none exists.
- Level
Hard9 of 10
- Topics
- Geometry, Brute force
- Solved
- No attempts yet
Problem
The island of Bytopia was ruled by King Byzar for a long time. When Byzar died without warning, his two sons Biteon and Byteon argued over how to divide the land of the island. In the end they agreed to cut the land into two pieces and take one each.
The land of Bytopia is a polygon with vertices. Every edge is parallel to the axis or to the axis, and two adjacent edges are perpendicular. Two edges that are not adjacent never meet, so the polygon is simple.
The princes want to cut this land into two congruent polygons with a single axis-parallel segment. Two polygons are congruent when one of them can be rotated or flipped so that it covers the other exactly. Both endpoints of the segment must have integer coordinates.
Decide whether such a segment exists, and if it does, find the one fixed by the output rule.
Input
The first line contains the number of vertices of the polygon (, is even).
Each of the next lines contains the coordinates and of a vertex, given in the order in which the vertices appear along the polygon ().
So the boundary of the land consists of the segments , , , , . Two adjacent segments are always perpendicular.
Output
If a segment that cuts the land into two congruent polygons exists, print its two endpoints and on one line, in the order . Either or must hold. Both endpoints must lie on the boundary of the polygon, and every point of the segment other than the two endpoints must lie in the interior of the polygon.
Several segments can satisfy these conditions. In that case pick exactly one by the following rule. First order the endpoints of each segment so that , that is, , or and . Then compare the four integers in this order and print the segment that comes first in lexicographic order.
If no such segment exists, print NO. Do not print the quotation marks.