题意:有n个点,找到一个顺序走遍这n个点,并且曼哈顿距离不超过25e8。

由于给的点坐标都在0-1e6之间。将x轴分成1000*1000,即1000长度为1块。将落在同一块的按y排序,编号为奇的块和偶的块一个升序,一个降序。有3个量值得关注。一是同一块中x的变化量,其实是不超过1000*n1,n1是第1块中点的数量。那么1000*n1+1000*n2......=1000*n<1e9。后两个量是同一块中y的高度差,另一个是本块最后一个和另一块第一个的高度差。这种做法下相邻两块这两个高度差的和是小于1.5e6的。1000块小于1.5e9。1e9+1.5e9刚好25e8。为什么高度差的和小于1.5e6?假设第k块是降序,Y的高度差是1e6,那么最低的一个点高度是0。如果它与下一块的第一个点的距离大于0.5e6,下一块所有点都要集中在上半部分,从而下一块的内部高度差就小于1e6。事实上,本块的最后一个点与下一块的第一个点的距离的增加必然导致下一块内部的高度差减小。

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
const double EPS=1e-;
struct nd{
int x,y,id;
nd(int a,int b,int _id):x(a),y(b),id(_id){}
};
vector<nd> vct[]; bool cmp1(nd &x,nd &y)
{
return x.y>y.y;
}
bool cmp2(nd &x,nd &y)
{
return x.y<y.y;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
int n;
cin>>n;
for(int i=;i<n;++i)
{
int a,b;
cin>>a>>b;
int block=a/;
vct[block].push_back(nd(a,b,i));
}
for(int i=;i<;++i)
{
if(i&)
{
sort(vct[i].begin(),vct[i].end(),cmp2);
}
else
{
sort(vct[i].begin(),vct[i].end(),cmp1);
}
}
bool ok=;
for(int i=;i<;++i)
{
for(int j=;j<vct[i].size();++j)
{
if(ok)cout<<" ";
cout<<vct[i][j].id+;
ok=;
}
}
return ;
}

codeforces 576c// Points on Plane// Codeforces Round #319(Div. 1)的更多相关文章

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

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

  2. codeforces 576C Points on Plane 相邻两点的欧拉距离

    题意:给出n个点,要求排序后,相邻两点的欧拉距离之和小于等于2.5e9做法:由于0≤ xi, yi ≤ 1e6,所以可以将x<=1000的点分成一份,1000<x<=2000的点分成 ...

  3. 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 ...

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

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

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

                                                                              C. Points on Plane On a pl ...

  6. Codeforces Round 319 # div.1 & 2 解题报告

    Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1< ...

  7. Codeforces Round #319 (Div. 2) E - Points on Plane

    题目大意:在一个平面里有n个点,点坐标的值在1-1e6之间,让你给出一个遍历所有点的顺序,要求每个点走一次,且 曼哈顿距离之和小于25*1e8. 思路:想了一会就有了思路,我们可以把1e6的x,y坐标 ...

  8. Points on Plane Codeforces - 576C

    https://www.luogu.org/problemnew/show/CF576C 看题面,一眼按莫队的方法排一下 直接交就会和我一样发现WA掉了... 算一下会发现,上限是3e9(块内左端点1 ...

  9. Codeforces Round #319 (Div. 1) B. Invariance of Tree 构造

    B. Invariance of Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/ ...

随机推荐

  1. Python: re.compile()

    compile(pattern,flags=0) 1.编译一个正则表达式模式,返回一个模式对象 2.第二个参数flags是匹配模式,可以使用按位或‘|'表示同时生效,也可以在正则表达式字符串中指定 P ...

  2. Hive 常用优化参数

    常用调优测试语句 :    ①显示当前hive环境的参数值: set 参数名; 如:   hive> set mapred.map.tasks;mapred.map.tasks;   ②设置hi ...

  3. quartz-job实现定时任务配置

    使用quartz开源调度框架,写服务实现在一些指定场景发送特定短信,创建一个实现org.quartz.Job接口的java类.Job接口包含唯一的方法: public void execute(Job ...

  4. adb shell 命令详解,android, adb logcat

    http://www.miui.com/article-275-1.html http://noobjava.iteye.com/blog/1914348 adb shell 命令详解,android ...

  5. Python3 打开 https 链接,异常:“SSL: CERTIFICATE_VERIFY_FAILED”

    Python3 打开 https 链接,异常:“SSL: CERTIFICATE_VERIFY_FAILED” 一.问题 Python2.7.9 之后,当使用urllib.urlopen打开一个 ht ...

  6. c++随机数及rand()的缺陷

    c++生成随机整数和浮点数如下: #include <random> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { ...

  7. VC中GetLastError()获取错误信息的使用,以及错误代码的含义

    转载:http://www.seacha.com/article.php/knowledge/windows/mfc/2011/0423/335.html VC中GetLastError()获取错误信 ...

  8. SQLSERVER中order by ,group by ,having where 的先后顺序

    SELECT [Name]  FROM [LinqToSql].[dbo].[Student]  where name='***' group  by  name    having (name='* ...

  9. Uncaught TypeError: $(...).daterangepicker is not a function

    本文为博主原创,未经允许不得转载: 在用bootstrap做一个日期插件的时候,代码和js,css等都是拷贝网上下载下来的实例,但是在 调试的时候,浏览器控制台一直报错 Uncaught TypeEr ...

  10. Windows下搭建FTP服务器

    一.什么是ftp? FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为“文传协议”.用于Internet上的控制文件的双向传输.同时,它也是一个应用程序(A ...