Rectangles
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given nn rectangles on a plane with coordinates of their bottom left and upper right points. Some (n−1)(n−1) of the given nnrectangles 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)(n−1) given rectangles.

Input

The first line contains a single integer nn (2≤n≤1326742≤n≤132674) — the number of given rectangles.

Each the next nn lines contains four integers x1x1, y1y1, x2x2 and y2y2 (−109≤x1<x2≤109−109≤x1<x2≤109, −109≤y1<y2≤109−109≤y1<y2≤109) — the coordinates of the bottom left and upper right corners of a rectangle.

Output

Print two integers xx and yy — the coordinates of any point that belongs to at least (n−1)(n−1) given rectangles.

Examples
input

Copy
3
0 0 1 1
1 1 2 2
3 0 4 1
output

Copy
1 1
input

Copy
3
0 0 1 1
0 1 1 2
1 0 2 1
output

Copy
1 1
input

Copy
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
output

Copy
1 1
input

Copy
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
output

Copy
3 4
Note

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.

题意:输出任意一个处于至少n-1个矩形相交区域的点

分析:考虑对于第i个矩形,如果不包括他,前面的i-1个矩形和后面的n-i个矩形是否可以有相交区域,如果有就一定有点处于其中,这个点也就位于n-1个矩形相交区域

   我们可以在开始的时候求出前面i个矩形的相交区域pre[i]和后面i个矩形的相交区域pos[i],然后再遍历一次循环求当前矩形前面的矩形和后面矩形的相交区域pre[i-1]相交pos[i+1]

AC代码:

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 232674;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
const double pi = acos(-1.0);
struct node {
ll x1, y1, x2, y2;
};
node a[maxn], pre[maxn], pos[maxn];
int main() {
ll n;
cin >> n;
for( ll i = 1; i <= n; i ++ ) {
cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
}
node st = a[1], ed = a[n];
pre[0].x1 = -2e9, pre[0].y1 = -2e9, pre[0].x2 = 2e9, pre[0].y2 = 2e9;
pos[n+1].x1 = -2e9, pos[n+1].y1 = -2e9, pos[n+1].x2 = 2e9, pos[n+1].y2 = 2e9;
for( ll i = 1, j = n; i <= n; i ++, j -- ) {
st.x1 = max(st.x1,a[i].x1), st.y1 = max(st.y1,a[i].y1);
st.x2 = min(st.x2,a[i].x2), st.y2 = min(st.y2,a[i].y2);
pre[i] = st;
ed.x1 = max(ed.x1,a[j].x1), ed.y1 = max(ed.y1,a[j].y1);
ed.x2 = min(ed.x2,a[j].x2), ed.y2 = min(ed.y2,a[j].y2);
pos[j] = ed;
}
for( ll i = 1; i <= n; i ++ ) {
node t;
t.x1 = max(pre[i-1].x1,pos[i+1].x1), t.y1 = max(pre[i-1].y1,pos[i+1].y1);
t.x2 = min(pre[i-1].x2,pos[i+1].x2), t.y2 = min(pre[i-1].y2,pos[i+1].y2);
if( t.x2-t.x1 >= 0 && t.y2-t.y1 >= 0 ) {
cout << t.x1 << " " << t.y1 << endl;
break;
}
}
return 0;
}

  

CF1028C Rectangles 思维的更多相关文章

  1. AIM Tech Round 5C. Rectangles 思维

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

  2. cf1028C. Rectangles(前缀和)

    题意 给出$n$个矩形,找出一个点,使得至少在$n$个矩阵内 Sol 呵呵哒,昨天cf半夜场,一道全场切的题,我没做出来..不想找什么理由,不会做就是不会做.. 一个很显然的性质,如果存在一个点 / ...

  3. Codeforces | CF1028C 【Rectangles】

    (这道题太简单啦...虽说我锤了一上午都没过...我能说这道题和\(CF1029C\)算是同一道题吗...) 按照时间顺序来说...\(CF1029\)在\(CF1028\)前面(而且\(CF1029 ...

  4. 【CF1028C】Rectangles(线段树)

    题意: n<=1e5,abs(x[i]),abs(y[i]<=1e9 思路:这是正解 离散后线段树强打,数据结构越学越傻 #include<cstdio> #include&l ...

  5. codeforces 1028C Rectangles【思维】

    题目:戳这里 题意:有n个矩阵,求一个点(保证存在)至少在n-1个点内. 解题思路:因为矩阵与坐标轴平行,所以我们画图可以发现如果存在点满足条件,则这些点中一定有一个是矩阵的顶点.我们可以把所有顶点的 ...

  6. 750. Number Of Corner Rectangles四周是点的矩形个数

    [抄题]: Given a grid where each entry is only 0 or 1, find the number of corner rectangles. A corner r ...

  7. [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序

    用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html  目录 马桶排序(令人 ...

  8. Photoshop、Illustrator思维导图笔记

    半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.

  9. CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维

    前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...

随机推荐

  1. 【SVN】SVN Working copy is too old

    前天在使用 SVN 客户端 CornerStone 的时候遇到了这个问题,代码不能提交了…… 遇到这个问题的时候怎么办? 解决办法: 找到报错对应的文件夹,里面有个 .svn 的文件夹,去掉再 com ...

  2. Windows下安装python2与python3以及分别对应的virtualenv

    第三次装python2与python3 除此之外还学会了如何在命令行复制代码1.单击右键2.菜单中选择标记3.按住左键选中需要复制的内容4.松开左键5.单击右键 全局中python版本为python2 ...

  3. 夯实Java基础(十四)——Java8新的日期处理类

    1.前言 Java8之前处理日期一直是Java程序员比较头疼的问题,从Java 8之后,Java里面添加了许多的新特性,其中一个最常见也是最实用的便是日期处理的类——LocalDate.LocalDa ...

  4. python基础--基于套接字进行文件传输、异常处理、socketserver模块

    异常处理: 什么是异常处理: 程序在运行过程中出现了不可预知的错误,并且该错误没有对应的处理机制,那么就会以异常的形式表现出来,造成的影响就是整个程序无法再正常运行 异常的结构: 异常的类型.异常的信 ...

  5. Go基础语法学习

    Go语言基础 Go是一门类似C的编译型语言,但是它的编译速度非常快.这门语言的关键字总共也就二十五个,比英文字母还少一个,这对于我们的学习来说就简单了很多.先让我们看一眼这些关键字都长什么样: 下面列 ...

  6. mac下使用zerobrane调试cocos2dx的lua

    环境:MacOSx 10.9.2, Lua 5.1.4, luaSocket 2.0.2, xcode5.0.2 所需文件 luasocket-2.0.2.zip,ZeroBraneStudioEdu ...

  7. 【Kubernetes 系列三】Kubernetes 学习文档推荐

    标题 地址 备注 Kubernetes 官方文档 https://kubernetes.io/docs 英文文档,全面 Kubernetes Handbook ttps://jimmysong.io/ ...

  8. MVP架构下解决 RxJava 自动解绑问题

    背景 MVP 模式下使用 RxJava 处理网络访问的回调,当数据返回时 Presenter 调用绑定的 View 的方法. 定义 BasePresenter 如下: public class Bas ...

  9. MVC+EF Core 完整教程20--tag helper详解

    之前我们有一篇:“动态生成多级菜单”,对使用Html Helper做了详细讲述,并且自定义了一个菜单的 Html Helper: https://www.cnblogs.com/miro/p/5541 ...

  10. 调用链系列(1):解读UAVStack中的贪吃蛇

    一.背景 对于分布式在线服务,一个请求需要经过多个系统中多个模块,可能多达上百台机器的协作才能完成单次请求.这种场景下单靠人力无法掌握整个请求中各个阶段的性能开销,更无法快速的定位系统中性能瓶颈.当发 ...