codeforces 577E E. Points on Plane(构造+分块)
题目链接:
2 seconds
256 megabytes
standard input
standard output
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.
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.
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.
5
0 7
8 10
3 4
5 0
9 12
4 3 1 2 5 题意: 现在给n个点,要求你找到一个顺序,这个顺序中的曼哈顿距离不能超过25*1e8; 思路: 构造的题,想到原来莫队算法中给数分块,然后降低复杂度的思想,然后我就想分块,然后看一下在最坏的情况下是否会超过上限;
按1e3的长度分块,然后这个块内要么按y的升序要么按Y的降序排列,这样每个块内平均下来最大的距离是1e3*1e3+1e6=2e6,一共1e3个块,所以一共2e9的距离符合要求;
还有就是要按块的位置升降序交替,使点呈现v和倒v的状态,不然每两个块相靠的地方会多出一个1e6,最后多了1e9就过不了了; AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const int mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e6+20;
const int maxn=1e3;
const double eps=1e-12; struct node
{
int x,y,id,pos;
}po[N];
int n;
int cmp(node a,node b)
{
if(a.pos==b.pos)
{
if(a.pos%2==1)return a.y<b.y;
return a.y>b.y;
}
return a.pos<b.pos;
}
int main()
{
read(n);
For(i,1,n)
{
read(po[i].x);
read(po[i].y);
po[i].pos=po[i].x/maxn;
po[i].id=i;
}
sort(po+1,po+n+1,cmp);
For(i,1,n)printf("%d ",po[i].id);
return 0;
}
codeforces 577E E. Points on Plane(构造+分块)的更多相关文章
- CF576C Points on Plane 构造
正解:构造 解题报告: 先放下传送门趴QAQ 话说我jio得这题好玄学啊,,,就是,我实在觉得我这题做得完美无缺了?可就是过不去,,,而且它告诉我的奇异错误是"wrong output fo ...
- 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 ...
- 构造 - Codeforces Round #319 (Div. 1)C. Points on Plane
Points on Plane Problem's Link Mean: 在二维坐标中给定n个点,求一条哈密顿通路. analyse: 一开始忽略了“无需保证路径最短”这个条件,一直在套最短哈密顿通路 ...
- Codeforces Round #319 (Div. 1)C. Points on Plane 分块思想
C. Points on Plane On a pl ...
- 【CodeForces】576 C. Points on Plane
[题目]C. Points on Plane [题意]给定坐标系中n个点的坐标(范围[0,10^6]),求一种 [ 连边形成链后总长度<=2.5*10^9 ] 的方案.n<=10^6. [ ...
- 题解 CF576C 【Points on Plane】
题解 CF576C [Points on Plane] 一道很好的思维题. 传送门 我们看这个曼哈顿距离,显然如果有一边是按顺序排列的,显然是最优的,那另一边怎么办呢? 假如你正在\(ioi\)赛场上 ...
- 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} ...
- Codeforces 576C. Points on Plane(构造)
将点先按x轴排序,把矩形竖着划分成$10^3$个块,每个块内点按y轴排序,然后蛇形走位上去. 这样一个点到下一个点的横坐标最多跨越$10^3$,一共$10^6$个点,总共$10^9$,一个块内最多走$ ...
- 构造+分块思想 Codeforces Round #319 (Div. 1) C
http://codeforces.com/contest/576/problem/C 题目大意: 给你一个曼哈顿距离的图,然后要求你找到一个链,链穿了所有的点 然后要求这链的长度<=25*10 ...
随机推荐
- [moka同学笔记]yii2.0数据库操作以及分页
1.model中models/article.php 1 <?php 2 3 namespace app\models; 4 5 use Yii; 6 7 /** 8 * This is the ...
- 【洛谷 p3368】模板-树状数组 2(数据结构)
题目:已知一个数列,你需要进行下面两种操作:1.将某区间每一个数数加上x:2.求出某一个数的和. 解法:树状数组+前缀和优化.数组中每位存和前一位的数的差,这样区间修改只用改两位,单点询问就是求前缀和 ...
- Win7下安装依赖lxml的python插件
博主python菜鸟,本想在win7下安装一个pyquery玩玩爬虫,折腾了好几天终于搞好了,发现python这坑不是一般的深啊. 有一部分没有截图,请谅解 python版本3.4 1.下载easy_ ...
- Linux下建立Nexus私服
Linux下建立Nexus私服 要安装3个东西,然后配置私服: 1.JDK 2.Maven 3.Nexus 然后配置 1.JDK的安装 下载JDK安装包,格式为RPM格式,安装即可 安装程序 #rpm ...
- Ettercap中间人攻击--介绍
前言 Ettercap有四种界面:Text,Curses,GTK2,Daemonize. -T 命令行界面,只显示字符.通常与配套的参数有-q(安静模式),加上该选项,则不会显示抓到的数据包 ...
- 用js实现在加载完成一个页面后自动执行一个方法
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- 同步推是如何给未越狱的IOS设备安装任意IPA的?
工作准备: 1. 准备一台MAC 2. 拥有一份299企业证书, 然后按照下面步骤操作: 1. 把xxxx.ipa改成xxx.zip, 解压缩得到Payload文件夹 2. 替换Payload里的em ...
- Android Studio安装使用图文教程(转)
[开发环境] 物理机版本:Win 7旗舰版(64位) Java SDK版本:jdk1.8.0_20(64位) Android SDK版本:Android 4.4(API 20) Android Stu ...
- IntelliJ IDEA 2016.2.4下载与注册码
下载地址 https://download.jetbrains.8686c.com/idea/ideaIU-2016.2.4.dmg 注册码 43B4A73YYJ-eyJsaWNlbnNlSWQiOi ...
- mysql中FIND_IN_SET的使用方法
在mysql中,有时我们在做数据库查询时,需要得到某字段中包含某个值的记录,但是它也不是用like能解决的,使用like可能查到我们不想要的记录,它比like更精准,这时候mysql的FIND_IN_ ...