AIM Tech Round 5C. Rectangles 思维

Posted mj-liylho

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AIM Tech Round 5C. Rectangles 思维相关的知识,希望对你有一定的参考价值。

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 (2n1326742≤n≤132674) — the number of given rectangles.

Each the next nn lines contains four integers x1x1, y1y1, x2x2 and y2y2 (?109x1<x2109?109≤x1<x2≤109, ?109y1<y2109?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.

技术分享图片

 

题意:给出n个矩形,找一个点至少同时在n-1个矩形内。

思路:我们分别对每条对角线求前缀交后缀交,则若在每个条对角线左右两边的的前缀与后缀取交后还存在交点,即为解。

代码:

 1 #include"bits/stdc++.h"
 2 
 3 #define db double
 4 #define ll long long
 5 #define vl vector<ll>
 6 #define ci(x) scanf("%d",&x)
 7 #define cd(x) scanf("%lf",&x)
 8 #define cl(x) scanf("%lld",&x)
 9 #define pi(x) printf("%d
",x)
10 #define pd(x) printf("%f
",x)
11 #define pl(x) printf("%lld
",x)
12 #define rep(i, n) for(int i=0;i<n;i++)
13 using namespace std;
14 const int N = 1e6 + 5;
15 const int mod = 1e9 + 7;
16 const int MOD = 998244353;
17 const db  PI = acos(-1.0);
18 const db  eps = 1e-10;
19 const ll  INF = 0x3fffffffffffffff;
20 int n;
21 struct P{
22     int d,l,u,r;
23     inline P operator | (P a){
24         return (P){max(a.d,d),max(a.l,l),min(a.u,u),min(a.r,r)};
25     }
26 }a[N],pre[N],suf[N];
27 int main(){
28     ci(n);
29     for(int i=1;i<=n;i++){
30        ci(a[i].d),ci(a[i].l),ci(a[i].u),ci(a[i].r);
31     }
32     pre[0]=suf[n+1]={-mod,-mod,mod,mod};//初始化
33     for(int i=1;i<=n;i++){
34         pre[i]=pre[i-1]|a[i];//前缀
35     }
36     for(int i=n;i>=1;i--){
37         suf[i]=suf[i+1]|a[i];//后缀
38     }
39     for(int i=1;i<=n;i++){
40         P tmp=pre[i-1]|suf[i+1];//取交
41         if(tmp.d<=tmp.u&&tmp.l<=tmp.r) return !printf("%d %d
",tmp.d,tmp.l);
42     }
43     return 0;
44 }

 

 

 
















以上是关于AIM Tech Round 5C. Rectangles 思维的主要内容,如果未能解决你的问题,请参考以下文章

AIM Tech Round 3 (Div. 2) B

AIM Tech Round 4 (Div. 2)

Codeforces AIM Tech Round3

AIM Tech Round 5 1028cf(A-E)

Codeforces_AIM Tech Round 3 (Div. 1)_A

AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)