#P9119. [春季测试 2023] 圣诞树

[春季测试 2023] 圣诞树

Problem Description

As everyone knows, Christmas in the year 3202 is coming soon, so little Ω\Omega bought a Christmas tree and a wire covered with colorful lights, and plans to wrap this wire around the tree.

The Christmas tree can be regarded as a convex polygon with nn vertices on a 2D plane. These nn vertices can be used to fix the wire, and they are numbered 1,,n1, \ldots, n in counterclockwise order. The coordinates of vertex ii are (xi,yi)(x_i, y_i). Let kk be the index of the vertex with the maximum yy-coordinate (if there are multiple such vertices, choose the one with the smallest index). It is not guaranteed that the vertex with index 11 has the smallest xx-coordinate.

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

Figure 2: A Christmas tree and one possible way to hang the wire

Little Ω\Omega wants to decorate this Christmas tree with the light-covered wire. For aesthetic reasons, she wants the wire to pass through every vertex exactly once. To connect to the power supply, the wire must start from (xk,yk)(x_k, y_k). Formally, she needs to decide a permutation p1,,pnp_1, \cdots, p_n of 1,,n1, \cdots, n such that p1=kp_1 = k. Then the wire starts from (xp1,yp1)(x_{p_1}, y_{p_1}) and passes through (xp2,yp2),,(xpn,ypn)(x_{p_2}, y_{p_2}), \cdots, (x_{p_n}, y_{p_n}) in order. The wire length is $\sum_{i=1}^{n-1}{\operatorname{d}((x_{p_i}, y_{p_i}), (x_{p_{i+1}}, y_{p_{i+1}}))}$.

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

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

To save cost, she wants you to find, among all possible plans, one that makes the wire length as short as possible. If the shortest plan is not unique, you only need to output any one of them.

Considering floating-point errors, your answer is accepted if the relative error or absolute error between your plan and the optimal plan in terms of segment lengths does not exceed 101010^{-10}.

Input Format

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

The next nn lines each contain two real numbers xi,yix_i, y_i accurate to 99 digits after the decimal point, representing the coordinates of vertex ii.

The data guarantees that these nn points are pairwise distinct, and connecting (x1,y1),(x2,y2),,(xn,yn)(x_1, y_1), (x_2, y_2), \cdots, (x_n, y_n) in order forms a convex polygon.

Output Format

Output one line containing nn positive integers p1,p2,,pnp_1, p_2, \cdots, p_n separated by single spaces, representing a permutation of 1,,n1, \cdots, n such that p1=kp_1 = k, and the wire length $\sum_{i=1}^{n-1}{\operatorname{d}((x_{p_i}, y_{p_i}), (x_{p_{i+1}}, y_{p_{i+1}}))}$ is minimal among all possible plans. If such a plan is not unique, output any one of them.

3
0.000000000 0.000000000
3.000000000 0.000000000
1.000000000 1.000000000

3 1 2

Hint

[Sample 1 Explanation]

In this sample, there are only the two plans shown in the figure below, with permutations 3,1,23, 1, 2 and 3,2,13, 2, 1. The wire lengths are 3+23 + \sqrt{2} and 3+53 + \sqrt{5}, and 3+2<3+53 + \sqrt{2} < 3 + \sqrt{5}.

Therefore, the answer permutation is 3,1,23, 1, 2.

Figure 3: All two possible plans for Sample 1

[Constraints]

For all data, it is guaranteed that 3n10003 \le n \le 1000 and xi,yi107|x_i|, |y_i| \le 10^7.

Test Point ID nn \le Special Property
1, 2 44 None
3, 4, 5, 6 99
7, 8, 9, 10, 11, 12 1818
13, 14 10310^3 A
15, 16 B
17, 18, 19, 20 None

Special property A: It is guaranteed that there exists a positive integer mnm \ge n such that the input nn vertices correspond to a consecutive segment of vertices of a regular mm-gon.

Special property B: It is guaranteed that x1<x2<<xnx_1 < x_2 < \cdots < x_n and y1>y2>>yny_1 > y_2 > \cdots > y_n.

Translated by ChatGPT 5