Rectilinear Polygon With Area Equal to Its Vertex Count
Time limit5sMemory limit128 MB
Given n, print a canonical rectilinear polygon outline with n vertices and area n, or NIE when n is odd or below 4.
- Level
Easy3 of 10
- Topics
- Implementation, Geometry, Math, Simulation
- Solved
- No attempts yet
Problem
A rectilinear polygon is a simple polygon whose edges are all parallel to the -axis or the -axis and in which every two consecutive edges are perpendicular (so the edges alternate between horizontal and vertical). The edges never touch or cross, except that two consecutive edges meet at their shared vertex.
You are given an integer . Consider rectilinear polygons that have exactly vertices and whose area equals exactly . Such a polygon does not exist for every , and when it exists there can be many of them, so this task asks for one specific canonical polygon defined in the Output section.
Input
The input contains a single integer (), the required number of vertices.
Output
A rectilinear polygon with exactly vertices and area exactly exists if and only if is even and . If it does not exist, print a single line containing the word NIE (Polish for "no").
Otherwise print the following canonical polygon. Let . Place unit-width vertical bars standing on the -axis; bar (for ) occupies the strip and has integer height , where:
- for : if is even, and if is odd;
- .
The outline of these bars is a simple rectilinear polygon with exactly vertices and area exactly . Print its vertices, one per line as two integers x y separated by a space, in counterclockwise order, in exactly this sequence: first , then , then ; then, for , the two points and ; and finally . (When the middle sequence is empty, so the polygon is the rectangle .)
No coordinate exceeds in absolute value.