题目链接:http://codeforces.com/contest/1028/problem/C
题目大意:给出n个矩形,求任意一个被至少n-1个矩形覆盖的点的坐标;
C. 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 nn 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)(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.
在codeforces上看的到大佬代码,又自己写了一遍 但时间是1996ms,擦线而过;
#include<iostream>
#include<set>
using namespace std;
multiset<int > mstx1,mstx2,msty1,msty2;
struct NODE{
int x1;
int y1;
int x2;
int y2;
}node[140000];
int main(){
int n;
cin>>n;
int a;
for(int i=0;i<n;i++){
cin>>node[i].x1>>node[i].y1>>node[i].x2>>node[i].y2;
mstx1.insert(node[i].x1);
msty1.insert(node[i].y1);
mstx2.insert(node[i].x2);
msty2.insert(node[i].y2);
}
for(int i=0;i<n;i++){
mstx1.erase(mstx1.find(node[i].x1));
msty1.erase(msty1.find(node[i].y1));
mstx2.erase(mstx2.find(node[i].x2));
msty2.erase(msty2.find(node[i].y2));
if(*mstx2.begin()>=*mstx1.rbegin() && *msty2.begin()>=*msty1.rbegin()){
cout<<*mstx2.begin()<<' '<<*msty2.begin()<<endl;
return 0;
}
mstx1.insert(node[i].x1);
mstx2.insert(node[i].x2);
msty1.insert(node[i].y1);
msty2.insert(node[i].y2);
}
return 0;
}