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.

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

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

代码:

 #include"bits/stdc++.h"

 #define db double
#define ll long long
#define vl vector<ll>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = ;
const db PI = acos(-1.0);
const db eps = 1e-;
const ll INF = 0x3fffffffffffffff;
int n;
struct P{
int d,l,u,r;
inline P operator | (P a){
return (P){max(a.d,d),max(a.l,l),min(a.u,u),min(a.r,r)};
}
}a[N],pre[N],suf[N];
int main(){
ci(n);
for(int i=;i<=n;i++){
ci(a[i].d),ci(a[i].l),ci(a[i].u),ci(a[i].r);
}
pre[]=suf[n+]={-mod,-mod,mod,mod};//初始化
for(int i=;i<=n;i++){
pre[i]=pre[i-]|a[i];//前缀
}
for(int i=n;i>=;i--){
suf[i]=suf[i+]|a[i];//后缀
}
for(int i=;i<=n;i++){
P tmp=pre[i-]|suf[i+];//取交
if(tmp.d<=tmp.u&&tmp.l<=tmp.r) return !printf("%d %d\n",tmp.d,tmp.l);
}
return ;
}

AIM Tech Round 5C. Rectangles 思维的更多相关文章

  1. codeforce AIM tech Round 4 div 2 B rectangles

    2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...

  2. AIM Tech Round 5 1028cf(A-E)

    AIM Tech Round 5 (codeforces上题目编号是1028)(A-E) ---完全被这次比赛打击,自己真的很渣--- 战况 依旧3题选手 被构造题坑得好惨 稍稍涨了rating,希望 ...

  3. AIM Tech Round 5 (rated, Div. 1 + Div. 2) C. Rectangles 【矩阵交集】

    题目传传传送门:http://codeforces.com/contest/1028/problem/C C. Rectangles time limit per test 2 seconds mem ...

  4. AIM Tech Round 5 (rated, Div. 1 + Div. 2) E(思维,构造)

    #include<bits/stdc++.h>using namespace std;long long a[150007];long long ans[150007];int main( ...

  5. AIM Tech Round 5 (rated, Div. 1 + Div. 2) D(SET,思维)

    #include<bits/stdc++.h>using namespace std;const long long mod = 1e9+7;char s[370007][27];long ...

  6. 【 AIM Tech Round 5 (rated, Div. 1 + Div. 2) C】Rectangles

    [链接] 我是链接,点我呀:) [题意] 给你n个矩形. 让你找出一个点(x,y) 使得这个点在其中至少(n-1)个矩形中. [题解] 若干个矩形交在一起的话. 它们所有的公共区域也会是一个矩形. 这 ...

  7. 【AIM Tech Round 4 (Div. 2) B】Rectangles

    [链接]http://codeforces.com/contest/844/problem/B [题意] 也是道计数水题,没什么记录意义 [题解] 枚举每个点的位置在,然后往右往下 枚举和它一样颜色的 ...

  8. AIM Tech Round 4 (Div. 2)ABCD

    A. Diversity time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

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

    A. Diversity time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

随机推荐

  1. Flask入门模板Jinja2语法与函数(四)

    1 模板的创建 模板文件结构: project/ templates/ 模板文件 跳转模板一般使用: from flask import render_template,render_template ...

  2. jQuery Mobile 移动 web 应用程序框架

    在这里我们主要讲一下如何引用jQuery Mobile(引用了jQuery Mobile,你就能引用jQuery Mobile里已经封装好的代码,让开发更加快捷简单) 从 CDN 引用 jQuery ...

  3. 实现动态代理(Java和spring)

    一.Java实现动态代理 1.创建接口 package com.oyy.mw.biz.i; public interface Cal { public int add(int num1,int num ...

  4. Oracle10g使用$ORACLE_HOME/rdbms/admin/awrrpt.sql报错

    Enter value for report_name: Using the report name awrrpt_1_591_593.htmlselect output from table(dbm ...

  5. 描边时消除锯齿SetSmoothingMode

    SmoothingModeAntiAlias 指定消除锯齿的呈现. SmoothingModeDefault 指定默认模式. SmoothingModeHighQuality 指定高质量.低速度呈现. ...

  6. Python语言程序设计基础(4)—— 程序的控制结构

    PM2.5 pm = eval(input()) if pm>=75: print("空气存在污染") else : print("空气没有污染") pr ...

  7. c#类的练习

    类部分练习题 - dijiaxing1234的博客 - CSDN博客  https://blog.csdn.net/dijiaxing1234/article/details/81230811 真好啊

  8. 基础算法之Dijkstra最短路径

    核心思想:以起始原点为中心,想外层扩展,知道扩展到重点为止. 设到A点的最短路径上,A点前驱节点为B,则该路径包含到达节点B的最短路径. S集合代表已经探索过的节点,U集合表示未探索过的节点. 时间复 ...

  9. o'Reill的SVG精髓(第二版)学习笔记——第一章

    1.1图形系统 计算机中描述图形信息的两大系统是栅格系统(raster graphics)和矢量图形(vector graphics) 1.1.4矢量图形的用途 ①计算机辅助绘图(CAD)程序. ②设 ...

  10. vue源码解读1

    前言 vue是一个非常典型的MVVM框架,它的核心功能一是双向数据绑定系统,二是组件化开发系统.那么本文是以一种通俗易懂的的角度来实现一个简单 的双向数据绑定系统,如果你用过vue却对vue的实现原理 ...