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 ...
随机推荐
- 1350. Canteen(map)
1350 这题没什么 就考一下map的用法吧 #include <iostream> #include<cstdio> #include<cstring> #in ...
- 关于SqlParameter中IN子句查询的问题
今天调试到方法中代码: String hotelCodes =”’’,’’,’’”; string sqltext ="select * from HotelMedalInfo where ...
- CodeForces Good Bye 2014 B. New Year Permutation
可能是因为这次没有分Div.1和Div.2,所以感觉题的难度比较大. 题意: 给出一个1~n的排列和一个邻接矩阵A,Aij = 1表示可以交换排列的第i项和第j项,问经过若干次交换后,求能够得到最小字 ...
- [转] struts.xml配置详解
转自:http://www.cnblogs.com/fmricky/archive/2010/05/20/1740479.html struts.xml是我们在开发中利用率最高的文件,也是Struts ...
- I.MX6 U-boot PWM hacking
/******************************************************************************* * I.MX6 U-boot PWM ...
- Java [Leetcode 292]Nim Game
问题描述: You are playing the following Nim Game with your friend: There is a heap of stones on the tabl ...
- Java [leetcode 26]Remove Duplicates from Sorted Array
题目描述: Given a sorted array, remove the duplicates in place such that each element appear only once a ...
- disabled
http://blog.csdn.net/dinglang_2009/article/details/6974887 如果把页面viewstate设为disabled 那么 ispost就一直为fal ...
- 使用VSS2005的时候报错:输入正确的服务器地址依然出错了
使用VSS2005的时候报错:输入正确的服务器地址依然出错了 使用VSS2005的时候报错: 在安装完vss客户端,进入vss服务器的时候,需要vss服务器的ip和数据库名称.以及初始化文件, 我在进 ...
- chmod命令
chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限.该命令有两种用法.一种是包含字母和操作符表达式的文字设定法:另一种是包含数字的数字设定法. Linux系统中的每 ...