博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round 97B 点分治
阅读量:6763 次
发布时间:2019-06-26

本文共 2744 字,大约阅读时间需要 9 分钟。

B. Superset
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A set of points on a plane is called good, if for any two points at least one of the three conditions is true:

  • those two points lie on same horizontal line;
  • those two points lie on same vertical line;
  • the rectangle, with corners in these two points, contains inside or on its borders at least one point of the set, other than these two. We mean here a rectangle with sides parallel to coordinates' axes, the so-called bounding box of the two points.

You are given a set consisting of n points on a plane. Find any good superset of the given set whose size would not exceed 2·105 points.

Input

The first line contains an integer n (1 ≤ n ≤ 104) — the number of points in the initial set. Next n lines describe the set's points. Each line contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — a corresponding point's coordinates. It is guaranteed that all the points are different.

Output

Print on the first line the number of points m (n ≤ m ≤ 2·105) in a good superset, print on next m lines the points. The absolute value of the points' coordinates should not exceed 109. Note that you should not minimize m, it is enough to find any good superset of the given set, whose size does not exceed 2·105.

All points in the superset should have integer coordinates.

Examples
input
Copy
2 1 1 2 2
output
Copy
3 1 1 2 2 1 2

题意:给定n个点,请添加一些点,使任意两点满足:

①在同一条水平线或竖直线上

②或构成一个矩形框住其他点。

输出添加最少点后,满足条件的点集。

思路:将点集按x从小到大排序,取中间的点m的x坐标做一条直线l,取其他的点在其上的投影,将这些点加入点集,此时点m与其他所有点之间都已满足条件且在l两端的任意两点也互相满足条件,之后将区间二分递归操作,即可得到最后的点集。

代码:

1 #include"bits/stdc++.h" 2 #include"cstdio" 3 #include"map" 4 #include"set" 5 #include"cmath" 6 #include"queue" 7 #include"vector" 8 #include"string" 9 #include"cstring"10 #include"ctime"11 #include"iostream"12 #include"cstdlib"13 #include"algorithm"14 #define db double15 #define ll long long16 #define vec vector
17 #define mt vector
18 #define ci(x) scanf("%d",&x)19 #define cd(x) scanf("%lf",&x)20 #define cl(x) scanf("%lld",&x)21 #define pi(x) printf("%d\n",x)22 #define pd(x) printf("%f\n",x)23 #define pl(x) printf("%lld\n",x)24 //#define rep(i, x, y) for(int i=x;i<=y;i++)25 #define rep(i, n) for(int i=0;i
P;34 P a[10005];35 set

s;36 void dfs(int l,int r)37 {38 int mid=(l+r)>>1;39 int x=a[mid].first;40 for(int i=l;i<=r;i++){41 s.emplace(P(x,a[i].second));//去重+不改变顺序42 }43 if(l

mid){47 dfs(mid+1,r);48 }49 50 }51 int main()52 {53 int n;54 ci(n);55 for(int i=0;i

 

 

转载于:https://www.cnblogs.com/mj-liylho/p/8995146.html

你可能感兴趣的文章
C#设计模式(1)——单例模式
查看>>
倒霉孩子,一个锁引发的冥想
查看>>
Mysql执行保错:Row 17 was cut by GROUP_CONCAT()
查看>>
MySQL Database Backup Methods Season 1 - mysqldump
查看>>
【BLE】蓝牙BLE 后台自动重连
查看>>
strstr()—字符串查找函数
查看>>
实现Exchange2003安全全集(下)
查看>>
ubuntu无密码登录
查看>>
ifup eth0失败,提示Error, some other host already uses address
查看>>
查看物理cpu & 核数 & 逻辑cpu个数
查看>>
华为交换机实现vrrp、dhcp、mstp及链路聚合
查看>>
java 中 instanceof 关键字
查看>>
浅谈linux用户管理与sudo授权
查看>>
sudo tcp_wrappe
查看>>
对Linux 系统中yum源的理解
查看>>
OSI数据封装和解封
查看>>
Linux I/O 重定向详解及应用实例
查看>>
解决Exchange DAG 1069/1564 cluster 问题
查看>>
nginx
查看>>
微信分享链接,如何自定义图片,标题,内容介绍
查看>>