10
14
2015
0

[Codeforces Round #319] Points on Plane


E. Points on Plane
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

On a plane are n points (xiyi) with integer coordinates between 0 and 106. The distance between the two points with numbers a and bis said to be the following value:  (the distance calculated by such formula is called Manhattan distance).

We call a hamiltonian path to be some permutation pi of numbers from 1 to n. We say that the length of this path is value .

Find some hamiltonian path with a length of no more than 25 × 108. Note that you do not have to minimize the path length.

Input

The first line contains integer n (1 ≤ n ≤ 106).

The i + 1-th line contains the coordinates of the i-th point: xi and yi (0 ≤ xi, yi ≤ 106).

It is guaranteed that no two points coincide.

Output

Print the permutation of numbers pi from 1 to n — the sought Hamiltonian path. The permutation must meet the inequality .

If there are multiple possible answers, print any of them.

It is guaranteed that the answer exists.

Sample test(s)
input
5
0 7
8 10
3 4
5 0
9 12
output
4 3 1 2 5 
Note

In the sample test the total distance is:

(|5 - 3| + |0 - 4|) + (|3 - 0| + |4 - 7|) + (|0 - 8| + |7 - 10|) + (|8 - 9| + |10 - 12|) = 2 + 4 + 3 + 3 + 8 + 3 + 1 + 2 = 26

题目大意:给出平面上的n个点$\left(x_i,y_i\right)$,定义$dist\left(i,j\right)=\left|x_i-x_j\right|+\left|y_i-y_j\right|$,求1~n的一个排列p,使得$\sum_{i=1}^{n-1}dist\left(p_i,p_{i+1}\right)\leq 2.5\times 10^9$。


将所有点按纵坐标分组,纵坐标1~1000一组,1001~2000一组,依此类推,每组都按横坐标排序,然后按之字形走,易证结果一定不会超过要求的值。

代码是用C#的LINQ写的,看不懂就算了。。

代码在此。

Category: 题解 | Tags: Codeforces 分块 | Read Count: 246

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com