题解 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. luogu P1592 互质

    题目描述 输入两个正整数n和k,求与n互质的第k个正整数. 输入输出格式 输入格式: 仅一行,为两个正整数n(≤10^6)和k(≤10^8). 输出格式: 一个正整数,表示与n互质的第k个正整数. 输 ...

  2. Http头 Range、Content-Range(http断点续传原理)

    HTTP头中一般断点下载时才用到Range和Content-Range实体头,Range用户请求头中,指定第一个字节的位置和最后一个字节的位置,如(Range:200-300)Content-Rang ...

  3. angular js 使用$location问题整理

    angular js 自带的$location方法十分强大,通过使用$location方法.我们能够获取到server的port.杂乱连接中的path()部分(/所包括的部分). 例: // give ...

  4. tomcat下配置https方式

    [本地HTTPS]①.<Connector SSLEnabled="true" clientAuth="false" keystoreFile=" ...

  5. JAVA_Error initializing endpoint怎么办

    1 运行CMD,输入命令netstat –ano,找到这个TCP,后缀为8080的PID(我的是2660),然后打开任务管理器,在进程选项卡中打开PID查看   2 在右侧的进程窗口找到PID是左侧的 ...

  6. hdu2955 Robberies (01背包)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=2955">http://acm.hdu.edu.cn/showproblem.php ...

  7. js传递默认形参

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  8. Java千百问_05面向对象(006)_is-a,has-a,like-a是什么

    点击进入_很多其它_Java千百问 1.is-a,has-a,like-a是什么 在面向对象设计的领域里,有若干种设计思路,主要有例如以下三种: is-a.has-a.like-a java中在类.接 ...

  9. swift菜鸟入门视频教程-05-控制流

    本人自己录制的swift菜鸟入门.欢迎大家拍砖.有什么问题能够在这里留言. 主要内容: For 循环 While 循环 条件语句 控制转移语句(Control Transfer Statements) ...

  10. 怎样给filter加入自己定义接口

    .在Cfilter类的定义中实现Interface接口的函数的定义: //-----------------------Interface methods----------------------- ...