#SRD0000144. Các điểm trên mặt phẳng (Points on Plane)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các điểm trên mặt phẳng (Points on Plane)
Points on Plane
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are pairwise distinct integer-coordinate points in the plane, numbered . Point has coordinates .
The Manhattan distance between points and is .
Find any permutation of such that the total Manhattan distance between consecutive points is at most :
$$\sum_{i=1}^{n-1}\left(|x_{p_i}-x_{p_{i+1}}|+|y_{p_i}-y_{p_{i+1}}|\right)\le2\,500\,000\,000.$$You do not need to minimize the length. A valid permutation is guaranteed to exist, and any valid permutation is accepted.
Input
- The first line contains integer .
- Each of the next lines contains , the coordinates of point .
Output
Print a permutation of the integers whose consecutive-point Manhattan distance sum satisfies the upper bound.
Subtasks
- Subtask 1 (20 points): ; integer coordinates ; all points distinct; total length at most .
- Subtask 2 (30 points): ; integer coordinates ; all points distinct; total length at most .
- Subtask 3 (50 points): ; integer coordinates ; all points distinct; total length at most .
Examples
Example 1
Input
5
0 7
8 10
3 4
5 0
9 12
Output
4 3 1 2 5
Explanation
The sample order is . The consecutive distances are , , , and ; total , below . Every index appears exactly once. Other permutations are also valid.
A different valid permutation is also accepted.