C. Rectangles

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值