题解 CF576C 【Points on Plane】

一道很好的思维题。

传送门

我们看这个曼哈顿距离,显然如果有一边是按顺序排列的,显然是最优的,那另一边怎么办呢?

假如你正在\(ioi\)赛场上,此时遇到一个\(n\le 10^6\)的题目,你现在发现自己的排列最坏情况是\(O(n^2)\)的,你怎么办?

可以莫队优化!

于是复杂度降到了\(O(n\sqrt{n})\)。

那么我们回来看,假设点是按\(x\)轴为关键字排序的,那么\(x\)方向产生的贡献最多是\(n\)的。

那么,算上\(y\)轴方向上的贡献,最终的答案是

\(f(n)=n+n\sqrt{n}\)

当\(n\le10^6\)时,

\(y=f(x),y_{min}=1001000000<2.5\times 10^9\)

于是这题就解决了。上代码:

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<bitset>
#include<vector>
#include<map>
#include<ctime>
#include<cstdlib>
#include<set>
#include<bitset>
#include<stack>
#include<list>
#include<cmath>
using namespace std;
#define RP(t,a,b) for(register int (t)=(a),edd_=(b);t<=edd_;++t)
#define DRP(t,a,b) for(register int (t)=(a),edd_=(b);t>=edd_;--t)
#define ERP(t,a) for(int t=head[a];t;t=e[t].nx)
#define Max(a,b) ((a)<(b)?(b):(a))
#define Min(a,b) ((a)<(b)?(a):(b))
#define TMP template<class ccf>
#define lef L,R,l,mid,pos<<1
#define rgt L,R,mid+1,r,pos<<1|1
#define midd register int mid=(l+r)>>1
#define chek if(R<l||r<L)return
#define all 1,n,1
#define pushup(x) seg[(x)]=seg[(x)<<1]+seg[(x)<<1|1]
typedef long long ll;
TMP inline ccf qr(ccf k){
char c=getchar();
ccf x=0;
int q=1;
while(c<48||c>57)
q=c==45?-1:q,c=getchar();
while(c>=48&&c<=57)
x=x*10+c-48,c=getchar();
if(q==-1)
x=-x;
return x;
}
const int maxn=1e6+15;
int be[maxn];
int N;
int n;
struct node{
int x,y,id;
inline void scan(int k){
x=qr(1);
y=qr(1);
id=k;
}
inline bool operator < (node z){
int dx=z.x;
int dy=z.y;
if(be[dx]==be[x]){
if(be[dx]&1)
return y<dy;
else
return y>dy;
}
else
return x<dx;
}
}data[maxn]; int main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
n=qr(1);
RP(t,1,n)
data[t].scan(t);
N=pow(n,0.5);
RP(t,1,maxn-15)
be[t]=(t-1)/N+1;
sort(data+1,data+n+1);
RP(t,1,n)
cout<<data[t].id<<' ';
cout<<endl;
return 0;
}

题解 CF576C 【Points on Plane】的更多相关文章

  1. CF576C Points on Plane 构造

    正解:构造 解题报告: 先放下传送门趴QAQ 话说我jio得这题好玄学啊,,,就是,我实在觉得我这题做得完美无缺了?可就是过不去,,,而且它告诉我的奇异错误是"wrong output fo ...

  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】576 C. Points on Plane

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

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

                                                                              C. Points on Plane On a pl ...

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

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

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

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

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

  8. Points on Plane Codeforces - 576C

    https://www.luogu.org/problemnew/show/CF576C 看题面,一眼按莫队的方法排一下 直接交就会和我一样发现WA掉了... 算一下会发现,上限是3e9(块内左端点1 ...

  9. Codeforces Round #319 (Div. 2) E - Points on Plane

    题目大意:在一个平面里有n个点,点坐标的值在1-1e6之间,让你给出一个遍历所有点的顺序,要求每个点走一次,且 曼哈顿距离之和小于25*1e8. 思路:想了一会就有了思路,我们可以把1e6的x,y坐标 ...

随机推荐

  1. centos7的时间同步机制:chrony使用

    配置时间同步方法如下: 1.安装chrony时间同步服务(系统默认安装) #yum install chrony 可以先查询一下是否有安装: [root@localhost etc]# rpm -qa ...

  2. SVN merge 三种方式

    1.Merge a range of revisions 2.Reintegrate a branch 3.Merge two different trees ———————————————————— ...

  3. Drools学习笔记

    Drools是一款基于Java的开源规则引擎 实现了将业务决策从应用程序中分离出来. 优点: 1.简化系统架构,优化应用 2.提高系统的可维护性和维护成本 3.方便系统的整合 4.减少编写“硬代码”业 ...

  4. 2017.2.28 activiti实战--第七章--Spring容器集成应用实例(五)普通表单

    学习资料:<Activiti实战> 第七章  Spring容器集成应用实例(五)普通表单 第六章中介绍了动态表单.外置表单.这里讲解第三种表单:普通表单. 普通表单的特点: 把表单内容写在 ...

  5. shell脚本中数组array常用技巧学习实践

    shell中数组的下标默认是从0开始的 1.将字符串放在数组中,获取其长度 #!/bin/bashstr="a b --n d"array=($str)length=${#arra ...

  6. PGM图片格式与代码

    这两天在搞神经网络,里面的一个人脸数据库的图片格式是PGM,事实上之前早就知道了这个图片格式,可是没去深究这个图片格式的数据究竟是什么安排的.搜索了下百度百科,发现介绍的真是简单,以下就自己来系统地整 ...

  7. Iowait的成因、对系统影响及对策

    什么是iowait?顾名思义,就是系统因为io导致的进程wait.再深一点讲就是:这时候系统在做io,导致没有进程在干活,cpu在执行idle进程空转,所以说iowait的产生要满足两个条件,一是进程 ...

  8. vue.js+koa2项目实战(二)创建 HeadBar 组件

    elementUI界面布局 1.创建 HeadBar 组件 HeadBar.vue <template> <el-row> <el-col :span="2&q ...

  9. IIS配置asp.net网站

    http://wenku.baidu.com/view/f8ce6c14767f5acfa0c7cd36.html

  10. Timer与ScheduledExecutorService间的抉择

    java.util.Timer计时器有管理任务延迟执行("如1000ms后执行任务")以及周期性执行("如每500ms执行一次该任务").但是,Timer存在一 ...