Codeforces 576C. Points on Plane(构造)
将点先按x轴排序,把矩形竖着划分成$10^3$个块,每个块内点按y轴排序,然后蛇形走位上去。
这样一个点到下一个点的横坐标最多跨越$10^3$,一共$10^6$个点,总共$10^9$,一个块内最多走$10^6$,一共$10^3$个块,一共$10^9$,跨过块的部分一共$2*10^6$,也就是总共不会超过$2*10^9+2*10^6$。
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=;
struct poi{int x, y, pos;}a[maxn];
int n, x;
void read(int &k)
{
int f=; k=; char c=getchar();
while(c<'' || c>'') c=='-' && (f=-), c=getchar();
while(c<='' && c>='') k=k*+c-'', c=getchar();
k*=f;
}
inline bool cmp1(poi a, poi b){return a.x<b.x;}
inline bool cmp2(poi a, poi b){return a.y<b.y;}
int main()
{
read(n);
for(int i=;i<=n;i++) read(a[i].x), read(a[i].y), a[i].pos=i;
sort(a+, a++n, cmp1); int now=;
for(int i=;i<=;i++)
{
x=i*;
int l=now, r=now;
for(;a[r].x<=x && r<=n;r++); r--;
if(l>r) continue;
sort(a++l, a++r, cmp2); now=r+;
if(i&) for(int j=l;j<=r;j++) printf("%d ", a[j].pos);
else for(int j=r;j>=l;j--) printf("%d ", a[j].pos);
}
}
Codeforces 576C. Points on Plane(构造)的更多相关文章
- codeforces 576c// Points on Plane// Codeforces Round #319(Div. 1)
题意:有n个点,找到一个顺序走遍这n个点,并且曼哈顿距离不超过25e8. 由于给的点坐标都在0-1e6之间.将x轴分成1000*1000,即1000长度为1块.将落在同一块的按y排序,编号为奇的块和偶 ...
- codeforces 576C Points on Plane 相邻两点的欧拉距离
题意:给出n个点,要求排序后,相邻两点的欧拉距离之和小于等于2.5e9做法:由于0≤ xi, yi ≤ 1e6,所以可以将x<=1000的点分成一份,1000<x<=2000的点分成 ...
- codeforces 577E E. Points on Plane(构造+分块)
题目链接: E. Points on Plane time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 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} ...
- CF576C Points on Plane 构造
正解:构造 解题报告: 先放下传送门趴QAQ 话说我jio得这题好玄学啊,,,就是,我实在觉得我这题做得完美无缺了?可就是过不去,,,而且它告诉我的奇异错误是"wrong output fo ...
- 构造 - 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 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/pro ...
- 【CodeForces】576 C. Points on Plane
[题目]C. Points on Plane [题意]给定坐标系中n个点的坐标(范围[0,10^6]),求一种 [ 连边形成链后总长度<=2.5*10^9 ] 的方案.n<=10^6. [ ...
- Codeforces Round #319 (Div. 1)C. Points on Plane 分块思想
C. Points on Plane On a pl ...
随机推荐
- 在spring boot上基于maven使用redis——批量匹配并删除 (二)
一.背景 在搭建了项目之后,由于需要通过触发动作,并删除redis中多个key. 二.思路 在查询了jedis并没有类似的删除方法之后,事情就变得清晰起来.完成上述任务,分为两个步骤,第一,找到要删除 ...
- 排查GCC 4.4.X版本优化switch-enum的BUG
起因 一次偶然碰到一个诡异的bug,现象是同一份C++代码使用GCC4.4.x版本在开启优化前和优化后的结果不一样,优化后的代码逻辑不正确. 示例代码如下: //main.cpp #include & ...
- 用vsstudio 设计Winform 高分屏上布局错乱的问题
在使用win10高分辨率150%,200%系统进行winform开发时, 会有布局错乱的现象,比如之前定义的300px的宽度,往往被设置成600px (200%分辨率下). 这个问题vs2015的解决 ...
- 大前端全栈CSS3移动端开发
作者声明:本博客中所写的文章,都是博主自学过程的笔记,参考了很多的学习资料,学习资料和笔记会注明出处,所有的内容都以交流学习为主.有不正确的地方,欢迎批评指正 本节课学习视频来源:https://ww ...
- wepy中如何使用stylus等样式预处理器
wepy中如何使用stylus等样式预处理器 一.如何在wepy中使用stylus 1.安装wepy-compiler-stylus(以及stylus, stylus-loader) npm inst ...
- 关于js中一个对象当做参数传递是按值传递还是按引用传递的个人看法
在<JavaScript高级程序设计>这本书中有这样一段话:有很多开发人员错误的认为:在局部作用域中修改的对象会在全局作用域中反映出来,就说明参数是按引用传递的.换句话说,尼古拉认为当一个 ...
- World Cup(思维+模拟)
Description Allen wants to enter a fan zone(球迷区) that occupies a round square and has nn entrances. ...
- scrum立会报告+燃尽图(第三周第五次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2286 项目地址:https://coding.net/u/wuyy694 ...
- [图算法] 1030. Travel Plan (30)
1030. Travel Plan (30) A traveler's map gives the distances between cities along the highways, toget ...
- 【vue】vue安装卡住/报错
网上有很多教程怎么安装: 安装cnpmnpm install -g cnpm --registry=https://registry.npm.taobao.org 升级npmcnpm install ...