TopcoderArchiveVisit Topcoder
TCO9 Oct 2018
TCO 19 SRM 739

MakePolygon

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given an int N. Your task is to generate any (not necessarily convex) polygon P such that:

  • The number of vertices of P must be exactly N.
  • P must be simple. (See Notes for the definition.)
  • Each coordinate of each vertex of P must be an integer between 1 and 25, inclusive.
  • P must have the smallest possible area (among all polygons that satisfy all previous constraints).

Suppose the vertices of the polygon you generated are (x0, y0), (x1, y1), (x2, y2), ..., (xN-1, yN-1) in order along its boundary (in either direction). Return a int[] with N elements. For each i, element i of the return value should be xi * 100 + yi. If there are multiple optimal polygons, you may return any of them.

Definition

Class:
MakePolygon
Method:
make
Parameters:
int
Returns:
int[]
Method signature:
int[] make(int N)
(be sure your method is public)

Notes

  • A simple polygon is a polygon such that the length of each side is positive, no two consecutive sides are parallel, and no two non-consecutive sides share a common point.
  • For the given constraints there is always at least one polygon that satisfies all the constraints.

Constraints

  • N will be between 3 and 500, inclusive.

Examples

  1. 3
    Returns: {101, 201, 102 }
    The example return value describes a triangle with vertices at (1,1), (2,1), and (1,2). The area of this triangle is 0.5, which is optimal.
  2. 4
    Returns: {101, 201, 202, 102 }
  3. 5
    Returns: {101, 201, 303, 202, 102 }
Back to all problems