AIM Tech Round 5C. Rectangles 思维
2 seconds
256 megabytes
standard input
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.
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.
Print two integers xx and yy — the coordinates of any point that belongs to at least (n−1)(n−1) given rectangles.
3
0 0 1 1
1 1 2 2
3 0 4 1
1 1
3
0 0 1 1
0 1 1 2
1 0 2 1
1 1
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
1 1
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
3 4
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 思维的更多相关文章
- 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 ...
- AIM Tech Round 5 1028cf(A-E)
AIM Tech Round 5 (codeforces上题目编号是1028)(A-E) ---完全被这次比赛打击,自己真的很渣--- 战况 依旧3题选手 被构造题坑得好惨 稍稍涨了rating,希望 ...
- 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 ...
- 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( ...
- 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 ...
- 【 AIM Tech Round 5 (rated, Div. 1 + Div. 2) C】Rectangles
[链接] 我是链接,点我呀:) [题意] 给你n个矩形. 让你找出一个点(x,y) 使得这个点在其中至少(n-1)个矩形中. [题解] 若干个矩形交在一起的话. 它们所有的公共区域也会是一个矩形. 这 ...
- 【AIM Tech Round 4 (Div. 2) B】Rectangles
[链接]http://codeforces.com/contest/844/problem/B [题意] 也是道计数水题,没什么记录意义 [题解] 枚举每个点的位置在,然后往右往下 枚举和它一样颜色的 ...
- 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 ...
- 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 ...
随机推荐
- C# 生成随机数重复问题
今天做测试,在一个循环里面给实体属性赋随机值,然后生成一个实体集合,突然发现生成的实体集合中的所有实体相应属性值都是一样的,调试时却又发现值并不是重复的,度娘以后发现了问题——Random类是一个产生 ...
- day011-网络编程
1. 网络编程概述 1.1 网络编程三要素 地址.端口.协议 1.1.1 IP地址:网络中设备的唯一标识. IPV4格式:xxx.xxx.xxx.xxx由四段数字组成,每一段数字由八位二进制数字组成 ...
- 3元购买微信小程序解决方案一个月
一.登录微信公众平台https://mp.weixin.qq.com/ 二.点击立即注册.注意:这里不要用微信公众号登录,小程序账号和微信公众号是不同的. 三.在注册页面点击小程序板块. 四.进入小程 ...
- javascript Object与Array用法
引用类型:引用类型是一种数据结构,用于将数据和功能组织在一起.引用类型的值是引用类型的一个实例. 一.Object ECMAScript中的对象其实就是一组数据和功能的结合. Object类型其实是所 ...
- 数据结构与算法分析java——散列
1. 散列的概念 散列方法的主要思想是根据结点的关键码值来确定其存储地址:以关键码值K为自变量,通过一定的函数关系h(K)(称为散列函数),计算出对应的函数值来,把这个值解释为结点的存储地址,将结点存 ...
- IOS 集成友盟分享
#import <Foundation/Foundation.h> @interface UMSocialSinaHandler : NSObject +(void)openSSOWith ...
- 【甘道夫】NN HA 对于 Client 透明的实验
之前转载过一篇[伊利丹]写的NN HA实验记录.该博客描写叙述了主备NN透明切换的过程,也就是说,当主NN挂掉后,自己主动将备NN切换为主NN了,Hadoop集群正常执行. 今天我继续做了一个实验.目 ...
- ACM-ICPC (10/20)
B. Bakery time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- csu 1947 三分
题意: 长者对小明施加了膜法,使得小明每天起床就像马丁的早晨一样. 今天小明早上6点40醒来后发现自己变成了一名高中生,这时马上就要做早操了,小明连忙爬起来 他看到操场密密麻麻的人,突然灵光一闪想到了 ...
- 关于TOCTTOU攻击的简介
前言 最近看到了一些以 at 结尾的Linux系统调用,在维基百科上面说这可以防御一些特定的TOCTTOU攻击,而在TOCTTOU对应页面中并没有中文版的介绍,而且百度的结果也比较少,于是决定抽空写一 ...