https://www.luogu.org/problemnew/show/CF576C

看题面,一眼按莫队的方法排一下

直接交就会和我一样发现WA掉了。。。

算一下会发现,上限是3e9(块内左端点1e9,块内右端点1e9,块间右端点移动1e9),大于题面的2.5e8

(出题人还真的造出数据把它卡掉了。。而且好像是要让它FST的样子,那些数据在很后面。。)

事实上,块间右端点移动是可以优化的!只要右端点一轮从坐标小的移到坐标大的,下一轮反过来,就可以减少这个1e9到一个相当少的数字

简单的实现方法就是,偶数块中小的移到大的,奇数块中反过来

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii; int n;
struct P
{
int fi,se,n;
};
P p[];
int bl[];
int sz;
bool c1(const P &a,const P &b)
{
return bl[a.fi]==bl[b.fi]?((bl[a.fi]&)?a.se<b.se:a.se>b.se):a.fi<b.fi;
}
int main()
{
int i;
scanf("%d",&n);sz=;
for(i=;i<=n;i++)
{
scanf("%d%d",&p[i].fi,&p[i].se);p[i].n=i;
}
for(i=;i<=;i++) bl[i]=i/sz;
sort(p+,p+n+,c1);
for(i=;i<=n;i++) printf("%d ",p[i].n);
return ;
}

Points on Plane Codeforces - 576C的更多相关文章

  1. codeforces 576c// Points on Plane// Codeforces Round #319(Div. 1)

    题意:有n个点,找到一个顺序走遍这n个点,并且曼哈顿距离不超过25e8. 由于给的点坐标都在0-1e6之间.将x轴分成1000*1000,即1000长度为1块.将落在同一块的按y排序,编号为奇的块和偶 ...

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

  3. codeforces 577E E. Points on Plane(构造+分块)

    题目链接: E. Points on Plane time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  4. 【CodeForces】576 C. Points on Plane

    [题目]C. Points on Plane [题意]给定坐标系中n个点的坐标(范围[0,10^6]),求一种 [ 连边形成链后总长度<=2.5*10^9 ] 的方案.n<=10^6. [ ...

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

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

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

                                                                              C. Points on Plane On a pl ...

  7. 题解 CF576C 【Points on Plane】

    题解 CF576C [Points on Plane] 一道很好的思维题. 传送门 我们看这个曼哈顿距离,显然如果有一边是按顺序排列的,显然是最优的,那另一边怎么办呢? 假如你正在\(ioi\)赛场上 ...

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

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

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

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

随机推荐

  1. html标签默认属性值之margin;padding值

    一.h1~h6标签:有默认margin(top,bottom且相同)值,没有默认padding值. 在chrome中:16,15,14,16,17,19; 在firefox中:16,15,14,16, ...

  2. 最全的Android源码目录结构详解【转】

    本文转载自:http://blog.csdn.net/yangwen123/article/details/8055025 Android 2.1|-- Makefile|-- bionic     ...

  3. sdutoj 2373 Black and white painting( 规律统计计算 3Y )

    Black and white painting 题目描述 You are visiting the Centre Pompidou which contains a lot of modern pa ...

  4. 渗透模型 Percolation Models(一个物理模型的广泛应用)

    转自:http://mooc.guokr.com/note/15357/ http://mooc.guokr.com/user/0298406005/note/ 模型思想: 有水流下来,是否会渗入地面 ...

  5. 【转载】Myeclipse中实现js的提示

    近期需要大量使用JS来开发,但是MyEclipse2014自带的JS编辑器没有代码提示的功能,开发效率有点低,所以安装了一个Spket的插件,过程非常简单,SVN插件的安装比这个更简单. Spket插 ...

  6. HihoCoder 1502 : 最大子矩阵 (双指针)

    描述 给定一个NxM的矩阵A和一个整数K,小Hi希望你能求出其中最大(元素数目最多)的子矩阵,并且该子矩阵中所有元素的和不超过K. 输入 第一行包含三个整数N.M和K. 以下N行每行包含M个整数,表示 ...

  7. 洛谷 2668&2540 斗地主——搜索+贪心+dp

    题目:https://www.luogu.org/problemnew/show/P2540 发现如果没有顺子,剩下的可以贪心.所以搜索顺子怎么出,然后贪心. 这样只能过不加强版.原因是贪心的时候难以 ...

  8. java单例的几种写法

    转载出处:http://cantellow.javaeye.com/blog/838473 第一种(懒汉,线程不安全): public class Singleton { private static ...

  9. zz 堆空间与栈空间

    http://blog.sina.com.cn/s/blog_7321be1101013aua.htmlhttp://soft.chinabyte.com/os/51/12324551.shtmlht ...

  10. monkey基本命令及脚本编写

    Monkey 是Android自带的黑盒测试工具,一般通过随机触发界面事件,来确定应用是否会发生异常,多用于android应用的稳定性.压力测试  基本命令: adb shell monkey [op ...