C. Rectangles

12 篇文章 0 订阅

C. Rectangles

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

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个矩阵的左下角坐标和右上角坐标。让你求出n-1个矩形中都包含有的那个点的坐标。

这道题跟之前的一道很像。

https://blog.csdn.net/xianpingping/article/details/82084106

上边的是去掉了这个是否满足。而这个是假设就是这个是否满足。

去掉当前的矩形,判断剩下的左下角的所有左端点要小于右上角的所有右端点,同理判断纵坐标即可。

#include<bits/stdc++.h>
using namespace std;
const int N=155555;
int a[N][4],n;
multiset<int>s[4];
int main(){
    cin>>n;              
    for(int i=0;i<n;i++)
        for(int j=0;j<4;j++)cin>>a[i][j],s[j].insert(a[i][j]);
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++)s[j].erase(s[j].find(a[i][j]));
        if(*s[0].rbegin()<=*s[2].begin()&&*s[1].rbegin()<=*s[3].begin()){
            cout<<*s[0].rbegin()<<" "<<*s[1].rbegin()<<endl;break;
        }
        for(int j=0;j<4;j++)s[j].insert(a[i][j]);
    }
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值