C. Rectangles
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]);
}
}
推荐阅读
-
c. 求阶乘和的方法(N的值不能太大)初学者
-
C.进程调度实例讲解
-
codeforces C. Count Triangles
-
Codeforces 1355 C. Count Triangles
-
codeforces C. K-th Not Divisible by n
-
Robert C. Martin对RoR的高度评价令我吃惊
-
VK Cup 2017 - Qualification 1 C. Cycle In Maze(bfs+最短路+贪心+思维)
-
VK Cup 2017 - Qualification 2 C. Online Courses In BSU(dfs)
-
Codeforces Round #320 (Div. 2) C. A Problem about Polyline ( 数学 )
-
Codeforces Round #654 (Div. 2)-C. A Cookie for You