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个点内. 解题思路:因为矩阵与坐标轴平行,所以我们画图可以发现如果存在点满足条件,则这些点中一定有一个是矩阵的顶点.我们可以把所有顶点的 ...
随机推荐
- redis的主从模式
主从通信过程 Master配置: 1:关闭rdb快照(备份工作交给slave) 2:可以开启aof slave配置: 1: 声明slave-of slaveof 192.168.0.102 2: 配置 ...
- 洛谷P1962 斐波那契数列(矩阵快速幂)
题目背景 大家都知道,斐波那契数列是满足如下性质的一个数列: • f(1) = 1 • f(2) = 1 • f(n) = f(n-1) + f(n-2) (n ≥ 2 且 n 为整数) 题目描述 请 ...
- webpack 参数1、context: path.resolve 2、path.join('', '..', 'aa') 3、 path.posix.join('static','/aa')
1.context: path.resolve 项目入口路径 2. 3.
- ASP版_阿里大于短信API Demo
阿里大于申请地址:http://www.alidayu.com 阿里大于短信发送Demo: ******index.asp************* <%@LANGUAGE="VBSC ...
- luoguP4512 【模板】多项式除法 NTT+多项式求逆+多项式除法
Code: #include<bits/stdc++.h> #define maxn 300000 #define ll long long #define MOD 998244353 # ...
- Shell(四)函数
函数 linux shell 可以用户定义函数,然后在shell脚本中可以随便调用. 一.格式 shell中函数的定义格式如下: [ function ] funname [()] { action; ...
- PHP下的Oauth2.0尝试 - OpenID Connect
OpenID Connect OpenID Connect简介 OpenID Connect是基于OAuth 2.0规范族的可互操作的身份验证协议.它使用简单的REST / JSON消息流来实现,和之 ...
- 新手须知 QT类大全
QT类大全,在行内容中罗列出来了,希望大家多看看,如果是API就更好了,但可惜不是.这些是一些大类,请多做参考. QApplication 应用程序类 QLabel 标签类 QPushButton 按 ...
- 集合接口list与集合接口set的区别
在Java中 除了 Map以外的集合的根接口都是Collection接口,而在Collection接口的子接口中,最重要的莫过于List和Set集合接口. 今天我们就来谈谈List集合接口与Set集合 ...
- java源码之HashSet
1,HashSet介绍 1)HashSet 是一个没有重复元素的集合.2)它是由HashMap实现的,不保证元素的顺序,而且HashSet允许使用 null 元素.3)HashSet是非同步的.如果多 ...