欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C. Rectangles

程序员文章站 2022-06-04 09:17:41
...

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.

C. Rectangles

The picture below shows the rectangles in the third and fourth samples.

C. Rectangles

题意:给你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]);
    }
}

 

相关标签: codeforces