Universal Cup Judging System

Universal Cup

시간 제한: 2.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓
통계

在二維平面上有 $N$ 個點 $p_1, p_2, \dots, p_N$。

點 $p_i$ 位於 $(X_i, Y_i)$。沒有任何兩個點具有相同的座標。

請構造點序列 $p = (p_1, p_2, \dots, p_N)$ 的一個排列 $q = (q_1, q_2, \dots, q_N)$,使其滿足以下條件,或者判斷是否不可能。

  • 對於所有 $1 \le i \le N - 2$,這三個點 $q_i, q_{i+1}, q_{i+2}$ 依此順序要麼共線,要麼形成一個逆時針轉向。
    • 更具體地說,設 $q_i$ 的座標為 $(x_i, y_i)$。則以下條件必須成立: $(x_{i+1} - x_i)(y_{i+2} - y_{i+1}) - (y_{i+1} - y_i)(x_{i+2} - x_{i+1}) \ge 0$。

請針對 $T$ 組測試資料求解此問題。

輸入格式

輸入按以下格式給出:

T
case1
case2
:
caseT

每組測試資料按以下格式給出:

N
X1 Y1
X2 Y2
:
XN YN
  • $1 \le T \le 100$
  • $3 \le N \le 3000$
  • $0 \le X_i, Y_i \le 10^9$
  • $(X_i, Y_i) \ne (X_j, Y_j)$($i \ne j$)
  • 所有測試資料中 $N$ 的總和不超過 $3000$
  • 所有輸入值皆為整數

輸出格式

輸出 $T$ 行。

對於第 $i$ 行,若第 $i$ 組測試資料不存在滿足條件的 $q$,請輸出 $-1$。

否則,設 $q = (p_{r_1}, p_{r_2}, \dots, p_{r_N})$。請依此順序輸出 $r_1, r_2, \dots, r_N$,並以空格分隔。

若存在多個合法答案,你可以輸出其中任意一個。

範例

範例輸入 1

1
9
2 4
2 3
2 2
1 1
4 4
4 3
5 2
5 1
6 5

範例輸出 1

6 9 2 3 5 1 8 7 4

說明

problem_17421_1.png

圖 1:範例的解釋。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1485EditorialOpen题解jianglyView
#1343EditorialOpen题解MilmonView

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.