链接

[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. Ubuntu关闭(重启)网络服务命令

    Ubuntu关闭网络服务命令: service network-manager stop 重启网络服务命令: service network-manager restart

  2. .NetCore Build Terminology

       .NETCore Command:    1.dotnet build 2.dotnet run 3.dotnet new classlib 4.dotnet new xunit 5.dotne ...

  3. January 29th, 2018 Week 05th Monday

    Losing all hope was freedom. 彻底绝望就是真正的自由. Losing all the hopes, and we are free to challenge everyth ...

  4. kafka集群环境搭建(Linux)

    一.准备工作 centos6.8和jvm需要准备64位的,如果为32位,服务启动的时候报java.lang.OutOfMemoryError: Map failed 的错误. 链接:http://pa ...

  5. Eclipse字体最好

    改变字体 windows->Preferences->General->Appearance->Colors and Fonts 右边选择Java ->Java Edit ...

  6. 不可不知 DDoS的攻击原理与防御方法

    DoS攻击.DDoS攻击和DRDoS攻击相信大家已经早有耳闻了吧!DoS是Denial of Service的简写就是拒绝服务,而DDoS就是Distributed Denial of Service ...

  7. ceph 集群故障恢复

    集群规划配置 master1    172.16.230.21master2    172.16.230.22master3 172.16.230.23node1 172.16.230.26node2 ...

  8. JavaScript高级程序设计学习(六)之设计模式

    每种编程语言都有其自己的设计模式.不禁让人疑惑设计模式是用来做什么?有什么用? 简单的说,设计模式是为了让代码更简洁,更优雅,更完美. 同时设计模式也会让软件的性能更好,同时也会让程序员们更轻松.设计 ...

  9. source 和sh 区别

    sh新建一个子shell进程,变量在主shell中无法获取 source在当前shell中执行脚本,变量在主shell即当前shell中可以获取 例子: 1.新建一个test.sh脚本,内容为:A=1 ...

  10. xpath 的使用

    如需转发,请注明出处:小婷儿的python  https://www.cnblogs.com/xxtalhr/p/10520271.html 有问题请在博客下留言或加作者微信:tinghai87605 ...