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/problem/C
Description
On a plane are n points (xi, yi) 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 Input
5
0 7
8 10
3 4
5 0
9 12
Sample Output
4 3 1 2 5
HINT
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
题意
给你一个曼哈顿距离的图,然后要求你找到一个链,链穿了所有的点
然后要求这链的长度<=25*10e8
题解:
就分块咯,分成1000块,每个块内y坐标最多走10e6长度,x坐标最多走n*10e3个,n表示一块内的点数
n是一个二次函数维护的东西……所以大概答案最后就是10e3(10e6+10e6) = 2*10e9
所以大概看看脸,就能把这道题AC了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000500
#define mod 1001
#define eps 1e-9
#define pi 3.1415926
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* pair<int,pair<int,int> > p[maxn]; int main()
{
int n=read();
for(int i=;i<n;i++)
{
p[i].first = read();p[i].first/=;
p[i].second.first = read();p[i].second.second = i;
}
sort(p,p+n);
for(int i=;i<n;i++)
printf("%d ",p[i].second.second+);
}
Codeforces Round #319 (Div. 1) C. Points on Plane 分块的更多相关文章
- Codeforces Round #319 (Div. 1)C. Points on Plane 分块思想
C. Points on Plane On a pl ...
- 构造 - Codeforces Round #319 (Div. 1)C. Points on Plane
Points on Plane Problem's Link Mean: 在二维坐标中给定n个点,求一条哈密顿通路. analyse: 一开始忽略了“无需保证路径最短”这个条件,一直在套最短哈密顿通路 ...
- Codeforces Round #319 (Div. 2) E - Points on Plane
题目大意:在一个平面里有n个点,点坐标的值在1-1e6之间,让你给出一个遍历所有点的顺序,要求每个点走一次,且 曼哈顿距离之和小于25*1e8. 思路:想了一会就有了思路,我们可以把1e6的x,y坐标 ...
- Codeforces Round #486 (Div. 3) D. Points and Powers of Two
Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvo ...
- Codeforces Round 319 # div.1 & 2 解题报告
Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1< ...
- codeforces 576c// Points on Plane// Codeforces Round #319(Div. 1)
题意:有n个点,找到一个顺序走遍这n个点,并且曼哈顿距离不超过25e8. 由于给的点坐标都在0-1e6之间.将x轴分成1000*1000,即1000长度为1块.将落在同一块的按y排序,编号为奇的块和偶 ...
- Codeforces Round #466 (Div. 2) -A. Points on the line
2018-02-25 http://codeforces.com/contest/940/problem/A A. Points on the line time limit per test 1 s ...
- Codeforces Round #245 (Div. 2) A. Points and Segments (easy) 贪心
A. Points and Segments (easy) Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
- Codeforces Round #466 (Div. 2) A. Points on the line[数轴上有n个点,问最少去掉多少个点才能使剩下的点的最大距离为不超过k。]
A. Points on the line time limit per test 1 second memory limit per test 256 megabytes input standar ...
随机推荐
- java正则表达式应用--验证字符串是否为数字(转载)
首先说一下java正则表达式的重点概念: 第一.相关类:Pattern.Matcher 第二.典型的调用顺序是 Pattern p = Pattern.compile("a*b") ...
- jQuery树叶掉落特效代码
代码使用方法 1.将index.html源文件中的JS设置代码插入到你的网页中 2.将style.css文件内容合并到你的页面样式表中 3.将jquery文件加载到你的页面中,请注意,这不是通用的jq ...
- 在MFC[转载]在MFC状态栏显示时间 状态栏显示时间
原文:在MFC状态栏显示时间,谢小哈皮儿 c/c++ vc 在mfc状态栏显示时间,在VC的控件中有个Status bar可以在窗体状态栏中添加日期和时间.其实通过简单的代码,你就能创建一个有时钟显示 ...
- 进程通信之一 使用WM_COPYDATA C++及C#实现 z
原文地址:http://blog.csdn.net/morewindows/article/details/6804157 进程间通信最简单的方式就是发送WM_COPYDATA消息.本文提供C++及C ...
- 解读四大移动web应用开发框架真相
[51CTO译文]近来关于新的移动网页框架及移动平台存在不少争论.平心而论,这些工具在条款内容方面的混乱与模糊也是造成大家误解的原因之一.我希望通过几条简短的评述来尽量清理这种认识层面上的混乱状态. ...
- 【ruby on rail 项目之 VPS下载机】
[idea] 感觉互联网上国内难以下载资源的资源,通过VPS下载后再拖回来,想做个集成功能的.这里定个计划.打算开始做,项目会在github上同步更新. [start]
- STM32的can现场总线实验心得
最近在搞stm32实验板的can现场总线实验,之前只是搞过STC51的串口通信,相比之下,发觉can总线都挺复杂的.开始时,知道自己是新手,只知道can总线跟串行通信,485通信,I2C通信一样都是用 ...
- Linq 两个集合模糊查询
1.Linq的likelist<string> l=new list<string>();l.add("ss")l.add("ss123" ...
- ASP.NET入门(class0612)
内容:掌握基于ASP.Net的Web开发,B/S结构原理.ASP.Net内部原理.状态管理(Cookie.Session.ViewState等).数据验证.普通ASP.Net控件.母版.ListVie ...
- Linux与Windows的8个不同
(整理来自网络) 对刚刚接触Linux的人来说,很容易从windows的观念去理解Linux系统.今天扒一扒Win和Linux之间常见的8个区别. 一.Linux终端输入密码不回显字符 用户的密码在L ...