题解 CF576C 【Points on Plane】
题解 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】的更多相关文章
- 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】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 ...
- 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 Round #319 (Div. 1)C. Points on Plane
Points on Plane Problem's Link Mean: 在二维坐标中给定n个点,求一条哈密顿通路. analyse: 一开始忽略了“无需保证路径最短”这个条件,一直在套最短哈密顿通路 ...
- 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} ...
- Points on Plane Codeforces - 576C
https://www.luogu.org/problemnew/show/CF576C 看题面,一眼按莫队的方法排一下 直接交就会和我一样发现WA掉了... 算一下会发现,上限是3e9(块内左端点1 ...
- Codeforces Round #319 (Div. 2) E - Points on Plane
题目大意:在一个平面里有n个点,点坐标的值在1-1e6之间,让你给出一个遍历所有点的顺序,要求每个点走一次,且 曼哈顿距离之和小于25*1e8. 思路:想了一会就有了思路,我们可以把1e6的x,y坐标 ...
随机推荐
- PHP处理Android的POST数据
今天用PHP开发Android网络数据接口的时候,发现Thinkphp的I函数(php的$_POST)并不能获取到androidpost过来的数据 Android代码如下: Map<String ...
- [LeetCode] 1.Two Sum 两数之和分析以及实现 (golang)
题目描述: /* Given an array of integers, return indices of the two numbers such that they add up to a sp ...
- su su- sudo
su的作用是变更为其它使用者的身份,超级用户除外,需要键入该使用者的密码. linux su 命令 建议大家切换用户的时候 使用 su - root 这样,否则可能发现某些命令执行不了 关于su .s ...
- 缺少 Google API 秘钥,因此 Chromium 的部分功能将无法使用
获取密钥(ID)教程: https://www.chromium.org/developers/how-tos/api-keys 获取密钥(ID)地址: https://cloud.google.co ...
- Genymotion下载模拟器失败解决方案
下载模拟器的时候经常出现下面的问题:(Connection timeout occurred) 解决方法: 1.查看你要下载的模拟器的版本,我要下的版本是6.0.0 2.到C:\Users\yourn ...
- hdu1420(C++)
数论中模的运算: a*b%n=(a%n)*(b%n)%c; (a+b)%n=(a%n+b%n)%n; 幂的模:A^n%c=r 于是A^(n+1)%c=A*r%c; #include<ios ...
- Java中对象、对象引用、堆、栈、值传递以及引用传递的详解
Java中对象.对象引用.堆.栈.值传递以及引用传递的详解 1.对象和对象引用的差别: (1).对象: 万物皆对象.对象是类的实例. 在Java中new是用来在堆上创建对象用的. 一个对象能够被多个引 ...
- distinct 与order by 一起用
distinct 后面不要直接跟Order by , 如果要用在子查询用用order by .
- Mongo JavaTest
import com.mongodb.MongoClient; import com.mongodb.DB; import com.mongodb.DBCollection; import com.m ...
- 四、Silverlight中使用MVVM(四)——演练
本来打算用MVVM实现CRUD操作的,这方面例子网上资源还挺多的,毕竟CRUD算是基本功了,因为最近已经开始学习Cailburn框架了,感觉时间 挺紧的,这篇就实现其中的更新操作吧. 功能很明确,当我 ...