链接

[http://codeforces.com/group/1EzrFFyOc0/contest/1028/problem/C]

题意

给你n个矩形的左下角和右上角坐标,问你至少包含在n-1个矩形的点的坐标,有多个随便输出一个

分析

分别从前到后和从后到前枚举矩形重叠的部分

分别有b[i]和c[i]保存从第一个到第i个的矩形重叠的小矩形和从后面倒着来第n个到第i个的矩形重叠的小矩形

任意两个矩形重叠的小矩形左下和右上坐标计算为

(max(a.xl,b.xl),max(a.yl,b.yl)) 就是交矩形的左下角坐标。

(min(a.xr,b.xr),min(a.yr,b.yr)) 就是交矩形的右上角坐标。

然后枚举去掉n个中的一个是否能构成矩形如果可以直接输出左下角坐标,否则继续枚举

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=150000;
ll inf=1e9+10;
struct node{
ll xl,yl,xr,yr;
}a[maxn],b[maxn],c[maxn],wo; bool jud(node g){ if(g.xl>g.xr||g.yl>g.yr) return 0;
return 1;
} int main(){
int n,i;
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//freopen("in.txt","r",stdin);
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i].xl>>a[i].yl>>a[i].xr>>a[i].yr; b[0].xl=b[0].yl=-inf;
b[0].xr=b[0].yr=inf;
for(i=1;i<=n;i++){
b[i].xl=max(a[i].xl,b[i-1].xl);
b[i].yl=max(a[i].yl,b[i-1].yl);
b[i].xr=min(a[i].xr,b[i-1].xr);
b[i].yr=min(a[i].yr,b[i-1].yr);
} c[n+1].xl=c[n+1].yl=-inf;
c[n+1].xr=c[n+1].yr=inf;
for(i=n;i>=1;i--){
c[i].xl=max(a[i].xl,c[i+1].xl);
c[i].yl=max(a[i].yl,c[i+1].yl);
c[i].xr=min(a[i].xr,c[i+1].xr);
c[i].yr=min(a[i].yr,c[i+1].yr);
}
if(jud(b[n-1])){
cout<<b[n-1].xl<<' '<<b[n-1].yl<<endl;
}
else if(jud(c[2])){
cout<<c[2].xl<<' '<<c[2].yl<<endl;
}
else{
for(i=2;i<n;i++){
wo.xl=max(b[i-1].xl,c[i+1].xl);
wo.yl=max(b[i-1].yl,c[i+1].yl);
wo.xr=min(b[i-1].xr,c[i+1].xr);
wo.yr=min(b[i-1].yr,c[i+1].yr);
if(jud(wo))
break;
}
cout<<wo.xl<<' '<<wo.yl<<endl;
}
return 0;
}

C. Rectangles的更多相关文章

  1. poj-1314 Finding Rectangles

    题目地址: http://poj.org/problem?id=1314 题意: 给出一串的点,有些点可以构成正方形,请按照字符排序输出. 因为这道题的用处很大, 最近接触的cv 中的Rectangl ...

  2. [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)

    Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...

  3. codeforces 713B B. Searching Rectangles(二分)

    题目链接: B. Searching Rectangles time limit per test 1 second memory limit per test 256 megabytes input ...

  4. White Rectangles[HDU1510]

    White Rectangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. Java基础之在窗口中绘图——绘制直线和矩形(Sketcher 2 drawing lines and rectangles)

    控制台程序. import javax.swing.JComponent; import java.util.*; import java.awt.*; import java.awt.geom.*; ...

  6. Counting Rectangles

    Counting Rectangles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1043 Accepted: 546 De ...

  7. UVA 10574 - Counting Rectangles 计数

    Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular ...

  8. Project Euler 85 :Counting rectangles 数长方形

    Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...

  9. HDU 2056 Rectangles

    Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  10. Number of Rectangles in a Grid

    Project Euler 85: Investigating the number of rectangles in a rectangular grid Number of Rectangles ...

随机推荐

  1. .net core 导出Excel(epplus 创建excel )

    [Route("getopenfrequencyexcel")] [HttpGet] public IActionResult GetOpenFrequencyExcel(int ...

  2. mysql启动失败一例

    操作系统版本:Ubuntu 13.04 mysql 版本:mysql-server-5.5 现象:突然之前接到报告说数据库启不来了.第一时间查看硬盘空间,看是否硬盘满了.发现空间使用正常. root@ ...

  3. python基础、字符串和if条件语句,while循环,跳出循环、结束循环

    一:Python基础 1.文件后缀名: .py 2.Python2中读中文要在文件头写: -*-coding:utf8-*- 3.input用法      n为变量,代指某一变化的值 n = inpu ...

  4. February 6th, 2018 Week 6th Tuesday

    To be is to be perceived. 存在即被感知. How to interpret this quote? Maybe it means that everything in you ...

  5. 查询css相关属性的网站

    mozalla developer netwoke https://developer.mozilla.org/zh-CN/docs/Web/CSS/background 布局,div+css:htt ...

  6. .whl文件打开方式 Python

    wheel文件本质上就是zip或者rar,只不过他更加方便python的安装以及使用.在之前的图片中我们只要使用pip install wheel 就可以安装wheel. 在安装了wheel之后我们可 ...

  7. 【转】URL编码(encodeURIComponent和decodeURIComponent)

    转自http://blog.jhonse.com/archives/2032.jhonse 最近在用CI框架的时候,发现一个问题,URL的GET方式链接时,如果用中文字符的话,就会出现问题,提示:链接 ...

  8. map && multimap

    map map 的意思是映射.用法一般是     map<char, int>mp 按照我的理解,map 类似于一个高级的数组.前面的数据类型 char 相当于下脚标,而数组元素的值就对应 ...

  9. php一致性hash算法

    原理部分转自:https://www.jianshu.com/p/e8fb89bb3a61 基本场景 比如你有 N 个 cache 服务器(后面简称 cache ),那么如何将一个对象 object ...

  10. Rinkeby中测试币的申请

    https://www.rinkeby.io/#faucet 从这个页面可以看见测试币的请求是有要求的,下面说明怎么做: 之前使用的是google账号,即第二种方式来获取.后面gmail出现了问题,一 ...