题目链接:

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.

Examples
input
  1. 5
    0 7
    8 10
    3 4
    5 0
    9 12
output
  1. 4 3 1 2 5
  2.  
  3. 题意:
  4.  
  5. 现在给n个点,要求你找到一个顺序,这个顺序中的曼哈顿距离不能超过25*1e8;
  6.  
  7. 思路:
  8.  
  9. 构造的题,想到原来莫队算法中给数分块,然后降低复杂度的思想,然后我就想分块,然后看一下在最坏的情况下是否会超过上限;
    1e3的长度分块,然后这个块内要么按y的升序要么按Y的降序排列,这样每个块内平均下来最大的距离是1e3*1e3+1e6=2e6,一共1e3个块,所以一共2e9的距离符合要求;
    还有就是要按块的位置升降序交替,使点呈现v和倒v的状态,不然每两个块相靠的地方会多出一个1e6,最后多了1e9就过不了了;
  10.  
  11. AC代码:
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <bits/stdc++.h>
  7. #include <stack>
  8. #include <map>
  9.  
  10. using namespace std;
  11.  
  12. #define For(i,j,n) for(int i=j;i<=n;i++)
  13. #define mst(ss,b) memset(ss,b,sizeof(ss));
  14.  
  15. typedef long long LL;
  16.  
  17. template<class T> void read(T&num) {
  18. char CH; bool F=false;
  19. for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
  20. for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
  21. F && (num=-num);
  22. }
  23. int stk[70], tp;
  24. template<class T> inline void print(T p) {
  25. if(!p) { puts("0"); return; }
  26. while(p) stk[++ tp] = p%10, p/=10;
  27. while(tp) putchar(stk[tp--] + '0');
  28. putchar('\n');
  29. }
  30.  
  31. const int mod=1e9+7;
  32. const double PI=acos(-1.0);
  33. const int inf=1e9;
  34. const int N=1e6+20;
  35. const int maxn=1e3;
  36. const double eps=1e-12;
  37.  
  38. struct node
  39. {
  40. int x,y,id,pos;
  41. }po[N];
  42. int n;
  43. int cmp(node a,node b)
  44. {
  45. if(a.pos==b.pos)
  46. {
  47. if(a.pos%2==1)return a.y<b.y;
  48. return a.y>b.y;
  49. }
  50. return a.pos<b.pos;
  51. }
  52. int main()
  53. {
  54. read(n);
  55. For(i,1,n)
  56. {
  57. read(po[i].x);
  58. read(po[i].y);
  59. po[i].pos=po[i].x/maxn;
  60. po[i].id=i;
  61. }
  62. sort(po+1,po+n+1,cmp);
  63. For(i,1,n)printf("%d ",po[i].id);
  64. return 0;
  65. }

  

  1.  

codeforces 577E E. Points on Plane(构造+分块)的更多相关文章

  1. CF576C Points on Plane 构造

    正解:构造 解题报告: 先放下传送门趴QAQ 话说我jio得这题好玄学啊,,,就是,我实在觉得我这题做得完美无缺了?可就是过不去,,,而且它告诉我的奇异错误是"wrong output fo ...

  2. Codeforces Round #319 (Div. 1) C. Points on Plane 分块

    C. Points on Plane Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/pro ...

  3. 构造 - Codeforces Round #319 (Div. 1)C. Points on Plane

    Points on Plane Problem's Link Mean: 在二维坐标中给定n个点,求一条哈密顿通路. analyse: 一开始忽略了“无需保证路径最短”这个条件,一直在套最短哈密顿通路 ...

  4. Codeforces Round #319 (Div. 1)C. Points on Plane 分块思想

                                                                              C. Points on Plane On a pl ...

  5. 【CodeForces】576 C. Points on Plane

    [题目]C. Points on Plane [题意]给定坐标系中n个点的坐标(范围[0,10^6]),求一种 [ 连边形成链后总长度<=2.5*10^9 ] 的方案.n<=10^6. [ ...

  6. 题解 CF576C 【Points on Plane】

    题解 CF576C [Points on Plane] 一道很好的思维题. 传送门 我们看这个曼哈顿距离,显然如果有一边是按顺序排列的,显然是最优的,那另一边怎么办呢? 假如你正在\(ioi\)赛场上 ...

  7. CodeForces 577E Points on Plane(莫队思维题)

    题目描述 On a plane are nn points ( x_{i}xi​ , y_{i}yi​ ) with integer coordinates between 00 and 10^{6} ...

  8. Codeforces 576C. Points on Plane(构造)

    将点先按x轴排序,把矩形竖着划分成$10^3$个块,每个块内点按y轴排序,然后蛇形走位上去. 这样一个点到下一个点的横坐标最多跨越$10^3$,一共$10^6$个点,总共$10^9$,一个块内最多走$ ...

  9. 构造+分块思想 Codeforces Round #319 (Div. 1) C

    http://codeforces.com/contest/576/problem/C 题目大意: 给你一个曼哈顿距离的图,然后要求你找到一个链,链穿了所有的点 然后要求这链的长度<=25*10 ...

随机推荐

  1. ExecutorService常用方法和newFixedThreadPool创建固定大小的线程池

    1.ExecutorService: 是一个接口,继承了Executor: public interface ExecutorService extends Executor { } 2.Execut ...

  2. (旧)子数涵数·C语言——指针

    一.什么是指针? 指针在百度的解释:是编程语言中的一个对象,利用地址,它的值直接指向(points to)存在电脑存储器中另一个地方的值. 也就是说,指针是用于指向某一内存单元. 简而化之,指针便是地 ...

  3. NLog在.NET Core Console Apps中的简单应用

    什么是NLog? NLog is a free logging platform for .NET with rich log routing and management capabilities. ...

  4. 为什么重新设计 ASP.NET?

    灵活的跨平台运行时需求 早期 .NET Framework 版本一直作为单一且全面的整体进行安装,每个新版本都包含了新功能和几乎所有早期功能,而鲜有删减,这就不可避免的造成Framework的体积的增 ...

  5. ServiceLocator是反模式

    关于ServiceLocator模式 http://www.cnblogs.com/hwade/archive/2011/01/30/CommonServiceLocator.html 为什么是Ant ...

  6. JS 面向对象 编程设计

    面向对象的语言有一个标志,即拥有类的概念,抽象实例对象的公共属性与方法,基于类可以创建任意多个实例对象,一般具有封装.继承.多态的特性!但JS中对象与纯面向对象语言中的对象是不同的,ECMA标准定义J ...

  7. C#源码500份

    C Sharp  短信发送平台源代码.rar http://1000eb.com/5c6vASP.NET+AJAX基础示例 视频教程 http://1000eb.com/89jcC# Winform ...

  8. ArcGIS制图之Maplex自动点抽稀

    制图工作中,大量密集点显示是最常遇到的问题.其特点是分布可能不均匀.数据点比较密集,容易造成空间上的重叠,影响制图美观.那么,如果美观而详细的显示制图呢? 主要原理 Maplex中对标注有很好的显示控 ...

  9. Failed to upgrade AX 2012 R3 Retail channel database from CU9 to CU11 if SQL Server version was lower than 2012

    I tried to upgrade AX 2012 R3 Retail channel database from CU9 to CU11 for client. after generated n ...

  10. sharepoint 顺序工作流创建

    顺序工作流提供了一系列有组织的步骤,一般情况下,步骤是逐一执行的. 1.新建 > 项目,选择 SharePoint解决方案 > 空项目: 2.部署为场解决方案 3.添加 > 新项,选 ...