题目链接: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.

这个代码是从大佬那里看来的,时间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;
}
本文解析了CodeForces竞赛中C题“Rectangles”的解决方案,该问题要求找到至少被n-1个给定矩形覆盖的一个整数坐标点。通过使用multiset存储矩形的边界坐标,并遍历每个矩形移除其坐标后检查剩余矩形是否仍有交集的方式,最终确定一个符合条件的坐标。
630

被折叠的 条评论
为什么被折叠?



