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两端的任意两点也互相满足条件,之后将区间二分递归操作,即可得到最后的点集。

代码:

 #include"bits/stdc++.h"
#include"cstdio"
#include"map"
#include"set"
#include"cmath"
#include"queue"
#include"vector"
#include"string"
#include"cstring"
#include"ctime"
#include"iostream"
#include"cstdlib"
#include"algorithm"
#define db double
#define ll long long
#define vec vector<ll>
#define mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
//#define rep(i, x, y) for(int i=x;i<=y;i++)
#define rep(i, n) for(int i=0;i<n;i++)
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = mod - ;
const int inf = 0x3f3f3f3f;
const db PI = acos(-1.0);
const db eps = 1e-;
using namespace std;
typedef pair<int,int> P;
P a[];
set <P> s;
void dfs(int l,int r)
{
int mid=(l+r)>>;
int x=a[mid].first;
for(int i=l;i<=r;i++){
s.emplace(P(x,a[i].second));//去重+不改变顺序
}
if(l<mid){
dfs(l,mid-);
}
if(r>mid){
dfs(mid+,r);
} }
int main()
{
int n;
ci(n);
for(int i=;i<n;i++){
ci(a[i].first),ci(a[i].second);
}
sort(a,a+n);
for(int i=;i<n;i++) s.insert(a[i]);
dfs(,n-);
pi(s.size());
for(auto &it: s){//遍历
printf("%d %d\n",it.first,it.second);
}
}
 

Codeforces Round 97B 点分治的更多相关文章

  1. Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)

    Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...

  2. Codeforces Round #372 (Div. 2)

    Codeforces Round #372 (Div. 2) C. Plus and Square Root 题意 一个游戏中,有一个数字\(x\),当前游戏等级为\(k\),有两种操作: '+'按钮 ...

  3. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  4. Educational Codeforces Round 64 部分题解

    Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...

  5. CFEducational Codeforces Round 66题解报告

    CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...

  6. Educational Codeforces Round 64部分题解

    Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...

  7. Codeforces Round #790 (Div. 4) A-H

    Codeforces Round #790 (Div. 4) A-H A 题目 https://codeforces.com/contest/1676/problem/A 题解 思路 知识点:模拟. ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. Python模块入门(二)

    一.模块的循环导入问题 在python工程中,由于架构不当,可能会出现模块间互相引用的情况.这时候需要通过一些方法来解决这个问题 1.重新设计架构,解决互相引用的关系. 2.把import语句放置在模 ...

  2. Python中open文件的各种打开模式

    对于Python打开文件的模式,总是记不住,这次在博客里记录一下 r+: Open for reading and writing.  The stream is positioned  at  th ...

  3. Python基础学习之语句和语法

    语句和语法 python语句中有一些基本规则和特殊字符: 井号键“#”表示之后的字符为python注释: 三引号(‘‘‘ ’’’)可以多行注释 换行“\n”是标准的行分隔符(通常一个语句一行): 反斜 ...

  4. MySQL一致性非锁定读

    一致性非锁定读(consistent nonlocking read)是指InnoDB存储引擎通过多版本控制(multi versionning)的方式来读取当前执行时间数据库中行的数据,如果读取的行 ...

  5. Uva 11582 巨大的斐波那契数 模运算

    题目链接:https://vjudge.net/contest/156903#problem/A 题意:计算 f(a^b)%n 分析: 1.斐波那契数列是 f(i+2) = f(i+1) + f(i) ...

  6. 轻量级HTTP服务器Nginx(配置与调试Nginx维护Nginx)

    轻量级HTTP服务器Nginx(配置与调试Nginx) 文章来源于南非蚂蚁   Nginx安装完毕后,会产生相应的安装目录,根据前面的安装路径,Nginx的配置文件路径为/opt/nginx/conf ...

  7. 百度非会员满速下载利器(IDM)Internet Download Manager v6.30.8 中文特别版

    下载利器(IDM)Internet Download Manager v6.30.8 中文特别版 所属分类:工具软件 应用平台:Windows 资源版本:v6.30.8 最后更新:2018年04月14 ...

  8. python_1_变量的使用

    print("hello word") name="Qi Zhiguang" print("My name is",name) name2= ...

  9. Qlikview 数据加载方法罗列

    以下是通常会用到的数据加载的方法,供大家参考: 1. 从文件加载: Data: Load *,RowNo() as InputKey; SQL SELECT ID,TEST,DATECREATED F ...

  10. (jdbc和cmd)sqlite数据迁入mysql(导入导出)

    从sqlite进行导出数据 进行cmd命令 第一步:sqlite3->.open [文件路径](打开连接)->.tables(这个是查看表是否有没有)->.cd [切换的盘符](这里 ...