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

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

题目链接:

题意:

给定一个点集

加入一些点后再把这个点集输出来。

加入完点后使得对于点集内随意2个点都满足以下2条中至少一条

1、在同一水平线上或在同一垂直线上

2、所围成的矩阵里有其它点。

思路:

平面分治

先把点按x轴排序,然后找到中间的点,做一条直线 x = a[mid].x;

然后把全部点都投影到这条直线上。那么对于左边的点就不须要再和右边的进行匹配了。

#pragma comment(linker, "/STACK:1024000000,1024000000")#include 
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;typedef pair
pii;const int inf = 1e9;template
inline bool rd(T &ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-'&&(c<'0'||c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?

0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } template <class T> inline void pt(T x) { if (x <0) { putchar('-'); x = -x; } if(x>9) pt(x/10); putchar(x%10+'0'); } #define N 10005 pii a[N], b[N*20]; int top, n; void dfs(int l, int r){ int mid = (l+r)>>1, maxx = a[mid].first; for(int i = l; i <= r; i++) b[top++] = pii(maxx, a[i].second); if(l < mid) dfs(l, mid-1); if(mid < r) dfs(mid+1, r); } void input(){ for(int i = 1; i <= n; i++) rd(a[i].first), rd(a[i].second); sort(a+1, a+1+n); top = 0; } void output(){ sort(b, b+top); top = unique(b, b+top)-b; pt(top); putchar('\n'); for(int i = 0; i < top; i++) pt(b[i].first), putchar(' '), pt(b[i].second), putchar('\n'); } int main(){ while(rd(n)){ input(); dfs(1, n); output(); } return 0; }

转载地址:http://szzum.baihongyu.com/

你可能感兴趣的文章
批处理学习笔记(一)--删除几天的文件(forfile)
查看>>
使用Symantec Backup Exec 对Exchange 2010 进行备份还原和灾难恢复系列之一
查看>>
xhprof php性能测试
查看>>
基于MVC+EasyUI的Web开发框架经验总结(10)--在Web界面上实现数据的导入和导出...
查看>>
Mysql数据库视图操作
查看>>
[培训]薛大龙@福建福州(2008.7.24-25)
查看>>
Linux运维学习历程-第十四天-磁盘管理(一)磁盘分区表类型与文件系统
查看>>
2016年4月20日作业
查看>>
4、Ansible配置和使用
查看>>
如何设计EDM邮件内容
查看>>
java_类型转换(转)
查看>>
EMC 存储 故障转移模式(Failover Mode)简介
查看>>
解决iis服务器 Server Application Error
查看>>
wget
查看>>
openjdk安装二
查看>>
信息、信息化与信息化营销
查看>>
https的网站用了百度分享后网站在浏览器中不安全解决方法
查看>>
我的友情链接
查看>>
Oracle shutdown immediate无法关闭数据库解决方法
查看>>
MySQL5.7杀手级新特性:GTID原理与实战
查看>>