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个点内. 解题思路:因为矩阵与坐标轴平行,所以我们画图可以发现如果存在点满足条件,则这些点中一定有一个是矩阵的顶点.我们可以把所有顶点的 ...
随机推荐
- Simula-Virtual function
Simula is the name of two simulation programming languages, Simula I and Simula 67, developed in the ...
- iOS9 & Xcode7 下设置LaunchImage启动图片 问题及解决
最近在学习iOS开发,碰到一个设置启动图片的问题,怎么也搞不定,综合网上种种资料后Done,现在把完整过程写一下. 这里以建立一个空的Single View Application 为演示基础. 1. ...
- 使用easyui combobox初始化+在input中触发下拉框+获取值
效果图: 1.html <input id="alarmLeve" class="easyui-combobox" name="alarmLev ...
- 在centos里安装Nginx
(1)下载Nginx的RPM包 wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx ...
- python的父类和子类中关于继承的不同版本的写法
Python 2.7中的继承 在Python 2.7中,继承语法稍有不同,ElectricCar 类的定义类似于下面这样: class Car(object): def __init__(self, ...
- vue项目中,如何对static文件夹下的静态文件添加时间戳,以达到清除缓存
例如config.js文件是存放在static文件夹下,里面存放的是websocket信息,需要经常改动.改动了以后由于缓存信息,使其不生效,因此需要对引入的文件添加时间戳. 最新方法: 注意转义符的 ...
- [luogu] P4551 最长异或路径(贪心)
P4551 最长异或路径 题目描述 给定一棵\(n\)个点的带权树,结点下标从\(1\)开始到\(N\).寻找树中找两个结点,求最长的异或路径. 异或路径指的是指两个结点之间唯一路径上的所有边权的异或 ...
- SQL在线学习网站
1.在线编写网页:http://sqlfiddle.com/ 2.SQL菜鸟教程:http://www.runoob.com/sql/sql-intro.html 3.SQL语句在线练习 http:/ ...
- strlen()函数对一个未初始化数组的处理
今天使用strlen时 ,发现一个问题,demo代码如下: #include <stdio.h> #include <stdlib.h> #include <string ...
- Mybatis 中 foreach collection 的三种用法
foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有 item,index,collection,open,separator,close. ...