QOJ.ac

QOJ

时间限制: 5 s 内存限制: 512 MB 总分: 100

#11151. Polygon

统计

On a plane, $n$ pairwise disjoint segments are drawn, each parallel to one of the axes of a Cartesian coordinate system. We want to construct a polygon with at most $20n$ sides parallel to the coordinate axes, such that $n$ of its sides coincide with these segments.

Any two consecutive sides of the polygon must be perpendicular; the sides of the polygon cannot have any common points, except for the vertices shared by two consecutive sides. Each segment from the input must be a side of the polygon. The coordinates of the endpoints of the drawn segments are integers, but the coordinates of the polygon vertices may be fractional.

Input

The first line of input contains a single integer $n$ ($1 \le n \le 100\,000$) representing the number of segments. The next $n$ lines describe the segments: each of these lines contains four integers $x_1, y_1, x_2, y_2$ ($-10^8 \le x_1, y_1, x_2, y_2 \le 10^8$), representing a segment with endpoints $(x_1, y_1)$ and $(x_2, y_2)$. Each segment has a non-zero length and is either vertical or horizontal. The segments do not have any common points.

Output

If it is impossible to construct a polygon satisfying the problem conditions, output the word NIE in a single line. Otherwise, in the first line of output, print the number $m$ ($m \le 20n$), representing the number of sides of the polygon. In the next $m$ lines, print the vertices of the polygon in the order of their occurrence along the perimeter of the polygon (in either direction): the $i$-th line should contain two numbers $x, y$ ($-10^9 \le x, y \le 10^9$) indicating that the coordinates of the $i$-th vertex of the polygon are $(x, y)$. Each of these numbers must be given in decimal notation and contain at most seven digits after the decimal point.

Note: For technical reasons, the description of the polygon printed by your program should not exceed 50 MB. If this limit is exceeded, you may receive an OLE (Output limit exceeded) error.

Examples

Input 1

5
-1 1 -1 -1
0 0 0 -1
0 1 2 1
2 -1 2 0
0 2 -2 2

Output 1

22
-1 1
-1 -1
-0.6 -1
-0.6 0
-0.4 0
-0.4 -1
0 -1
0 0
1.4 0
1.4 -1
1.8 -1
1.8 0
2 0
2 -1
2.4 -1
2.4 2
2 2
2 1
0 1
0 2
-2 2
-2 1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.