QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#5716. Christmas Tree

統計

As is well known, Christmas in the year 3202 is approaching, so Little $\Omega$ has bought a Christmas tree and a wire covered in fairy lights, and she intends to wrap this wire around the Christmas tree.

The Christmas tree can be viewed as a convex polygon with $n$ vertices in a two-dimensional plane. These $n$ vertices can be used to fix the wire, and they are numbered $1, \dots, n$ in clockwise order. The coordinates of the $i$-th vertex are $(x_i, y_i)$. Let $k$ be the index of the vertex with the maximum $y$-coordinate (if there are multiple such vertices, choose the one with the smallest index).

The left side of the figure below shows the outline of a Christmas tree, where the vertex with the maximum $y$-coordinate has index $k = 5$.

Figure 2: A Christmas tree and a possible wiring scheme

Little $\Omega$ wishes to decorate this Christmas tree with the wire covered in fairy lights. For aesthetic reasons, she wants the wire to pass through every vertex exactly once. To connect to the power source, the wire must start from $(x_k, y_k)$. Formally, she needs to determine a permutation $p_1, \dots, p_n$ of $1, \dots, n$ such that $p_1 = k$, and the wire starts from $(x_{p_1}, y_{p_1})$ and passes through $(x_{p_2}, y_{p_2}), \dots, (x_{p_n}, y_{p_n})$ in order. The length of the wire is then $\sum_{i=1}^{n-1} d((x_{p_i}, y_{p_i}), (x_{p_{i+1}}, y_{p_{i+1}}))$.

  • Here, $d$ is the Euclidean distance in the plane, i.e., $d((x, y), (x', y')) = \sqrt{(x - x')^2 + (y - y')^2}$.

The right side of the figure above shows one possible scheme, where the corresponding permutation is $5, 4, 8, 6, 3, 9, 1, 7, 2$.

To save costs, she wants you to provide a scheme that minimizes the length of the wire among all possible schemes. If there is more than one scheme that results in the shortest wire length, you only need to output any one of them.

Considering the errors caused by floating-point numbers, your output scheme is considered correct if the relative or absolute error of the wire length compared to the optimal wire length does not exceed $10^{-10}$.

Input

The first line contains a positive integer $n$, representing the number of vertices of the Christmas tree.

The next $n$ lines each contain two real numbers $x_i, y_i$ with 9 decimal places, representing the coordinates of the vertex with index $i$.

The data guarantees that these $n$ points are distinct, and connecting them in the order $(x_1, y_1), (x_2, y_2), \dots, (x_n, y_n)$ forms a convex polygon.

Output

Output a single line containing $n$ positive integers $p_1, p_2, \dots, p_n$ separated by single spaces, representing a permutation of $1, \dots, n$ such that $p_1 = k$, and the wire length $\sum_{i=1}^{n-1} d((x_{p_i}, y_{p_i}), (x_{p_{i+1}}, y_{p_{i+1}}))$ is the shortest among all possible schemes. If there is more than one such scheme, output any one of them.

Examples

Input 1

3
0.000000000 0.000000000
3.000000000 0.000000000
1.000000000 1.000000000

Output 1

3 1 2

Note 1

In this example, there are only two possible schemes as shown in the figure below, corresponding to the permutations $3, 1, 2$ or $3, 2, 1$. The wire lengths are $3 + \sqrt{2}$ and $3 + \sqrt{5}$ respectively, and $3 + \sqrt{2} < 3 + \sqrt{5}$.

Therefore, the permutation corresponding to the answer is $3, 1, 2$.

Figure 3: All two possible schemes for Example 1

Input 2

See tree/tree2.in and tree/tree2.ans in the contestant directory.

Output 2

See tree/tree2.in and tree/tree2.ans in the contestant directory.

Input 3

See tree/tree3.in and tree/tree3.ans in the contestant directory.

Output 3

See tree/tree3.in and tree/tree3.ans in the contestant directory.

Input 4

See tree/tree4.in and tree/tree4.ans in the contestant directory. This data satisfies special property A.

Output 4

See tree/tree4.in and tree/tree4.ans in the contestant directory.

Input 5

See tree/tree5.in and tree/tree5.ans in the contestant directory. This data satisfies special property B.

Output 5

See tree/tree5.in and tree/tree5.ans in the contestant directory.

Input 6

See tree/tree6.in and tree/tree6.ans in the contestant directory.

Output 6

See tree/tree6.in and tree/tree6.ans in the contestant directory.

Constraints

For all data, it is guaranteed that $3 \le n \le 1000$; $|x_i|, |y_i| \le 10^7$.

Test Case ID $n \le$ Special Property
1, 2 4
3, 4, 5, 6 9 None
7, 8, 9, 10, 11, 12 18
13, 14 $10^3$ A
15, 16 $10^3$ B
17, 18, 19, 20 $10^3$ None

Special Property A: It is guaranteed that there exists a positive integer $m \ge n$ such that the input $n$ vertices correspond to a contiguous segment of vertices of a regular $m$-gon.

Special Property B: It is guaranteed that $x_1 < x_2 < \dots < x_n$ and $y_1 > y_2 > \dots > y_n$.

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.