题解 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\)

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

  1. #include<iostream>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<cstdio>
  5. #include<queue>
  6. #include<bitset>
  7. #include<vector>
  8. #include<map>
  9. #include<ctime>
  10. #include<cstdlib>
  11. #include<set>
  12. #include<bitset>
  13. #include<stack>
  14. #include<list>
  15. #include<cmath>
  16. using namespace std;
  17. #define RP(t,a,b) for(register int (t)=(a),edd_=(b);t<=edd_;++t)
  18. #define DRP(t,a,b) for(register int (t)=(a),edd_=(b);t>=edd_;--t)
  19. #define ERP(t,a) for(int t=head[a];t;t=e[t].nx)
  20. #define Max(a,b) ((a)<(b)?(b):(a))
  21. #define Min(a,b) ((a)<(b)?(a):(b))
  22. #define TMP template<class ccf>
  23. #define lef L,R,l,mid,pos<<1
  24. #define rgt L,R,mid+1,r,pos<<1|1
  25. #define midd register int mid=(l+r)>>1
  26. #define chek if(R<l||r<L)return
  27. #define all 1,n,1
  28. #define pushup(x) seg[(x)]=seg[(x)<<1]+seg[(x)<<1|1]
  29. typedef long long ll;
  30. TMP inline ccf qr(ccf k){
  31. char c=getchar();
  32. ccf x=0;
  33. int q=1;
  34. while(c<48||c>57)
  35. q=c==45?-1:q,c=getchar();
  36. while(c>=48&&c<=57)
  37. x=x*10+c-48,c=getchar();
  38. if(q==-1)
  39. x=-x;
  40. return x;
  41. }
  42. const int maxn=1e6+15;
  43. int be[maxn];
  44. int N;
  45. int n;
  46. struct node{
  47. int x,y,id;
  48. inline void scan(int k){
  49. x=qr(1);
  50. y=qr(1);
  51. id=k;
  52. }
  53. inline bool operator < (node z){
  54. int dx=z.x;
  55. int dy=z.y;
  56. if(be[dx]==be[x]){
  57. if(be[dx]&1)
  58. return y<dy;
  59. else
  60. return y>dy;
  61. }
  62. else
  63. return x<dx;
  64. }
  65. }data[maxn];
  66. int main(){
  67. #ifndef ONLINE_JUDGE
  68. freopen("in.in","r",stdin);
  69. freopen("out.out","w",stdout);
  70. #endif
  71. n=qr(1);
  72. RP(t,1,n)
  73. data[t].scan(t);
  74. N=pow(n,0.5);
  75. RP(t,1,maxn-15)
  76. be[t]=(t-1)/N+1;
  77. sort(data+1,data+n+1);
  78. RP(t,1,n)
  79. cout<<data[t].id<<' ';
  80. cout<<endl;
  81. return 0;
  82. }

题解 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. PHP处理Android的POST数据

    今天用PHP开发Android网络数据接口的时候,发现Thinkphp的I函数(php的$_POST)并不能获取到androidpost过来的数据 Android代码如下: Map<String ...

  2. [LeetCode] 1.Two Sum 两数之和分析以及实现 (golang)

    题目描述: /* Given an array of integers, return indices of the two numbers such that they add up to a sp ...

  3. su su- sudo

    su的作用是变更为其它使用者的身份,超级用户除外,需要键入该使用者的密码. linux su 命令 建议大家切换用户的时候 使用 su - root 这样,否则可能发现某些命令执行不了 关于su .s ...

  4. 缺少 Google API 秘钥,因此 Chromium 的部分功能将无法使用

    获取密钥(ID)教程: https://www.chromium.org/developers/how-tos/api-keys 获取密钥(ID)地址: https://cloud.google.co ...

  5. Genymotion下载模拟器失败解决方案

    下载模拟器的时候经常出现下面的问题:(Connection timeout occurred) 解决方法: 1.查看你要下载的模拟器的版本,我要下的版本是6.0.0 2.到C:\Users\yourn ...

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

  7. Java中对象、对象引用、堆、栈、值传递以及引用传递的详解

    Java中对象.对象引用.堆.栈.值传递以及引用传递的详解 1.对象和对象引用的差别: (1).对象: 万物皆对象.对象是类的实例. 在Java中new是用来在堆上创建对象用的. 一个对象能够被多个引 ...

  8. distinct 与order by 一起用

    distinct 后面不要直接跟Order by , 如果要用在子查询用用order by .

  9. Mongo JavaTest

    import com.mongodb.MongoClient; import com.mongodb.DB; import com.mongodb.DBCollection; import com.m ...

  10. 四、Silverlight中使用MVVM(四)——演练

    本来打算用MVVM实现CRUD操作的,这方面例子网上资源还挺多的,毕竟CRUD算是基本功了,因为最近已经开始学习Cailburn框架了,感觉时间 挺紧的,这篇就实现其中的更新操作吧. 功能很明确,当我 ...