1028C:Rectangles
You are given n rectangles on a plane with coordinates of their bottom left and upper right points. Some (n−1) of the given n
rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
Find any point with integer coordinates that belongs to at least (n−1)
given rectangles.
Input
The first line contains a single integer n(2≤n≤132674) — the number of given rectangles.
Each the next n lines contains four integers x1, y1, x2 and y2 (−109≤x1<x2≤109, −109≤y1<y2≤109) — the coordinates of
the bottom left and upper right corners of a rectangle.
Output
Print two integers x
and y — the coordinates of any point that belongs to at least (n−1)
given rectangles.
Examples
3
0 0 1 1
1 1 2 2
3 0 4 1
1 1
3
0 0 1 1
0 1 1 2
1 0 2 1
1 1
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
1 1
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
3 4
The picture below shows the rectangles in the first and second samples. The possible answers are highlighted.
The picture below shows the rectangles in the third and fourth samples.
暴力枚举+线段树优化
只要满足左下角的坐标的最小值大于等于右上角的坐标的最大值一定有公共区间
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
int a[][],n;
int tree[][<<];
void build(int l,int r,int root,int dep)
{
tree[dep][root]=dep>?INF:-INF;
if(l==r){
tree[dep][root]=a[l][dep];
return ;
}
int mid=l+r>>;
build(l,mid,root<<,dep);
build(mid+,r,root<<|,dep);
tree[dep][root]=dep>?min(tree[dep][root<<],tree[dep][root<<|]):max(tree[dep][root<<],tree[dep][root<<|]);
}
int query(int l,int r,int root,int L,int R,int dep)
{
if(L>R) return dep>?INF:-INF;
if(L<=l && R>=r){
return tree[dep][root];
}
int ans=dep>?INF:-INF,mid=l+r>>;
if(L<=mid) ans=dep>?min(ans,query(l,mid,root<<,L,R,dep)):max(ans,query(l,mid,root<<,L,R,dep));
if(R>mid) ans=dep>?min(ans,query(mid+,r,root<<|,L,R,dep)):max(ans,query(mid+,r,root<<|,L,R,dep));
return ans;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++){
for(int j=;j<;j++)
scanf("%d",&a[i][j]);
}
for(int i=;i<;i++)
build(,n,,i);
for(int i=;i<=n;i++)
{
int b[];
for(int j=;j<;j++){
if(j>) b[j]=min(query(,n,,,i-,j),query(,n,,i+,n,j));
else b[j]=max(query(,n,,,i-,j),query(,n,,i+,n,j));
}
if(b[]<=b[] && b[]<=b[]) return printf("%d %d\n",b[],b[]),;
}
return ;
}
1028C:Rectangles的更多相关文章
- 3.25考试(hnoi难度)----神奇的一日游
T1怕老婆 有一天hzy9819,来到了一座大城市拥有了属于他自己的一双滑板鞋.但是他还是不满足想要拥有属于自己的一栋楼,他来到了一条宽敞的大道上,一个一个记录着这些楼的层数以方便自己选择. hzy9 ...
- 【Ray Tracing The Next Week 超详解】 光线追踪2-6 Cornell box
Chapter 6:Rectangles and Lights 今天,我们来学习长方形区域光照 先看效果 light 首先我们需要设计一个发光的材质 /// light.hpp // ------- ...
- 850. 矩形面积 II
我们给出了一个(轴对齐的)矩形列表 rectangles . 对于 rectangle[i] = [x1, y1, x2, y2],其中(x1,y1)是矩形 i 左下角的坐标,(x2,y2)是该矩形右 ...
- [libgdx游戏开发教程]使用Libgdx进行游戏开发(6)-添加主角和道具
如前所述,我们的主角是兔子头.接下来我们实现它. 首先对AbstractGameObject添加变量并初始化: public Vector2 velocity; public Vector2 term ...
- java web 开发三剑客 -------电子书
Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...
- 所有selenium相关的库
通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...
- Project Euler 85 :Counting rectangles 数长方形
Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...
- Codeforces 372B Counting Rectangles is Fun:dp套dp
题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问( ...
- codeforces 1028C Rectangles【思维】
题目:戳这里 题意:有n个矩阵,求一个点(保证存在)至少在n-1个点内. 解题思路:因为矩阵与坐标轴平行,所以我们画图可以发现如果存在点满足条件,则这些点中一定有一个是矩阵的顶点.我们可以把所有顶点的 ...
随机推荐
- 服务端 | Linux 学习总结 (一)
http://billie66.github.io/TLCL/book/ 1.Ubuntu && linux shell 命令 Ubuntu两个重要版本:12.04和14.04 在终端 ...
- Android Handler学习笔记
已经习惯了挖坑不填,继续任性一下,周一到周五继续挖坑,每周六周日负责填坑. 1.从Android UI线程谈起 出于性能考虑,Android 中的UI操作并不是线程安全的,所以Android中规定只能 ...
- SQL Server 检测到基于一致性的逻辑 I/O 错误
背景:新建DB_GZN 恢复数据库备份文件 执行: select * from VI_MPS_PAPLT 错误提示: 消息 824,级别 24,状态 2,第 2 行 SQL Serv ...
- oc与swift比较
swift试是用语言层面的雕虫小技和oc的机制大道进行pk. 从整体上来说,oc是一个更加优秀的语言.
- POJ 3370 Halloween treats( 鸽巢原理简单题 )
链接:传送门 题意:万圣节到了,有 c 个小朋友向 n 个住户要糖果,根据以往的经验,第i个住户会给他们a[ i ]颗糖果,但是为了和谐起见,小朋友们决定要来的糖果要能平分,所以他们只会选择一部分住户 ...
- 51nod 1392 装盒子(费用流)
如果权值为\(1\)就是最长反链. 然而并不是.考虑用费用流. 把每一个盒子\(i\)拆成i和\(i+n\). 设源点为\(S\),汇点为\(T\). \(S\)向每一个i连容量为\(1\),费用为\ ...
- Numpy的使用规则
之前安装的python版本是3.7 各种库都是自己一个一个下载安装的 很操心 各种缺功能 后来发现了anaconda 啊 真是一个好东西 简单来说 它就是一个涵盖大部分常用库的python包 一次安装 ...
- Python学习笔记(一):基本数据类型
在Python3种,有六种标准数据类型: 数字(Number) 字符串(String) 列表(List) 元组(Tuple) 集合(Set) 字典(Dictionary) 这六种数据类型中,数字类型和 ...
- Java基础学习总结(57)——Jrebel插件热部署
JavaEE开发环境下,Tomcat对热布署的支持还是比较弱,致使开发过程中浪费大量时间在重启服务上.胖先生讨厌来来回回的折腾,所以想看看有没有实时的编译,发现Jrebel的插件付费软件,它对热布署的 ...
- 数据结构实现(四)二叉查找树java实现
转载 http://www.cnblogs.com/CherishFX/p/4625382.html 二叉查找树的定义: 二叉查找树或者是一颗空树,或者是一颗具有以下特性的非空二叉树: 1. 若左子树 ...