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.

Example

Input
2
1 1
2 2
Output
3
1 1
2 2
1 2
大致题意:给定一些点,要求添加一些点,使得任意一对点满足三个条件之一即可:1.横坐标相同.2.纵坐标相同.3.两个点围成的矩形内部或边上有其他的点.
分析:构造题,看到平面上分布着一些点,想到了平面上的分治.常见的方法是取中间点为中轴,左右两边分治.关键是两边的答案不好合并.
一开始的想法是枚举位于左边的点再枚举位于右边的点,如果两个点之间没有其它点,就必须在另外两个拐角之一放一个点,这样还要分类讨论,而且枚举的复杂度高,不是很好.在网上看到了其他人的构造方法,非常巧妙:以中间的点的所在的竖线为中轴,其他所有点向中轴投影,投影的点即为要添加的点.这样既满足了矩形内部有点的性质,又使得新添加的点全部在一条直线上,不用再对新添加的点来继续讨论.感觉平面上的分治都和中轴有关,以后这类问题要多往这个方向上想.
最后要去重,点数可能比10w要多,数组要开大一点.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; struct node
{
int x,y;
}e[],ans[],print[]; int n,cnt,tot; bool cmp(node a,node b)
{
if (a.x == b.x)
return a.y < b.y;
return a.x < b.x;
} void solve(int l,int r)
{
if (l == r)
ans[++cnt] = e[l];
if (l >= r)
return;
int mid = (l + r) >> ;
solve(l,mid - );
solve(mid + ,r);
for (int i = l; i <= r; i++)
{
node temp;
temp.x = e[mid].x;
temp.y = e[i].y;
ans[++cnt] = temp;
}
} int main()
{
scanf("%d",&n);
for (int i = ; i <= n; i++)
scanf("%d%d",&e[i].x,&e[i].y);
sort(e + ,e + + n,cmp);
solve(,n);
sort(ans + ,ans + + cnt,cmp);
print[++tot] = ans[];
for (int i = ; i <= cnt; i++)
if (ans[i].x != ans[i - ].x || ans[i].y != ans[i - ].y)
print[++tot] = ans[i];
printf("%d\n",tot);
for (int i = ; i <= tot; i++)
printf("%d %d\n",print[i].x,print[i].y); return ;
}
 

Codeforces 97.B Superset的更多相关文章

  1. CodeForces 97 E. Leaders(点双连通分量 + 倍增)

    题意 给你一个有 \(n\) 个点 \(m\) 条边的无向图,有 \(q\) 次询问,每次询问两个点 \(u, v\) 之间是否存在长度为奇数的简单路径. \(1 \le n, m, q \le 10 ...

  2. codeforces 97 div2 C.Replacement 水题

    C. Replacement time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  3. Codeforces Beta Round #97 (Div. 1) C. Zero-One 数学

    C. Zero-One 题目连接: http://codeforces.com/contest/135/problem/C Description Little Petya very much lik ...

  4. Codeforces Beta Round #97 (Div. 1) B. Rectangle and Square 暴力

    B. Rectangle and Square 题目连接: http://codeforces.com/contest/135/problem/B Description Little Petya v ...

  5. Codeforces Beta Round #97 (Div. 1) A. Replacement 水题

    A. Replacement 题目连接: http://codeforces.com/contest/135/problem/A Description Little Petya very much ...

  6. 【57.97%】【codeforces Round #380A】Interview with Oleg

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. Educational Codeforces Round 97 (Rated for Div. 2) E. Make It Increasing(最长非下降子序列)

    题目链接:https://codeforces.com/contest/1437/problem/E 题意 给出一个大小为 \(n\) 的数组 \(a\) 和一个下标数组 \(b\),每次操作可以选择 ...

  8. Educational Codeforces Round 97 (Rated for Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1437 A. Marketing Scheme 题解 令 \(l = \frac{a}{2}\),那么如果 \(r < ...

  9. Codeforces Beta Round #97 (Div. 1)

    B 判矩阵的时候 出了点错 根据点积判垂直 叉积判平行 面积不能为0 #include <iostream> #include<cstdio> #include<cstr ...

随机推荐

  1. 3.5星|《哈佛商学院最受欢迎的领导课》:讲给CEO的管理学常识、常见错误和改进方法

    哈佛商学院最受欢迎的领导课 英文版出版于2011年,还不算旧.中信2013年出过一版,这版估计是英文书版权过期后重新购买了再出版. 全书以写给CEO的口吻讲了许多管理常识,包含一些CEO容易犯的问题和 ...

  2. EasyUI tree 优化--点击文字折叠展开效果

    $(function () { $('#tree_menu').tree({ onSelect: function (node) { if (node.state == "closed&qu ...

  3. Redis的数据类型以及每种数据类型的使用场景

    人就是很奇怪的动物,很简单的问题往往大家都容易忽略,当我们在使用分布式缓存Redis的时候,一个最简单的问题Redis的数据类型以及每种数据类型的使用场景是什么? 是不是觉得这个问题很基础?我也这么觉 ...

  4. 关于XSS的一些知识点

    安全套接层(SSL)无助于减少XSS攻击.当Web浏览器使用SSL的时候,在网络中传送的数据是经过加密的,但是因为XSS攻击是在客户机器上发生的,所以数据已经被解密了,这时,攻击者仍然能够利用XSS安 ...

  5. Markdown分级语法手册

    目录 前言(可以不看) 基本语法(18) 1. 标题:# 2. 无序列表:- 3. 有序列表:1. 4. 斜体:* 5. 粗体:** 6. 加粗斜体:*** 7. 删除线:~~ 8. 分隔线:--- ...

  6. 关于jsonp跨域的 实现

    1.实现原理    1.把接口写在 script标签的src 中 这个接口就可以访问(不会存在跨域问题  因为接口在浏览器地址栏是可以访问的  会返回json字符串); 2.直接写不可以  因为正常情 ...

  7. Python Requests库入门——应用实例-京东商品页面爬取+模拟浏览器爬取信息

    京东商品页面爬取 选择了一款荣耀手机的页面(给华为打广告了,荣耀play真心不错) import requests url = "https://item.jd.com/7479912.ht ...

  8. 【探路者】Alpha发布用户使用报告

    预期统计用户使用数量:13人. 博文内容:1用户列表.2评论列表.3统计与总结 1用户列表: 二.评论内容 用户1:1不够好看.2不应该是中国地图为背景,蛇头是人物头像的么?(那是宣传片,不是预览图) ...

  9. 我是一只IT小小鸟观后感

    知道有这么一本写“码农”经历的书,是在大一下学期的第一堂职业生涯规划课上.也是抱着蛮看一看的心态在某宝上买了印刷版的开始抱着“啃”. 看了之后还是很有感触的,首先虽然现在我们是大学的软件学院中读书,但 ...

  10. myeclipse和ecplise中安装git插件的问题

    我的myeclipse10.7和ecplise helis一直安装不了git插件,myeclipse中details说我的myeclipse少了team_features等之类文件,helis的情况大 ...