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 ...
随机推荐
- Laravel 单元测试-模拟认证的用户
在 Laravel 编写单元测试时经常会遇到需要模拟认证用户的时候,比如新建文章.创建订单等,那么在 Laravel unit test 中如何来实现呢? 官方解决方法 Laravel 的官方文档中的 ...
- LESS初体验
将一个变量赋值给另一个变量,用引号:@white: 'color-white';,使用另一个变量,需要双@@符号:p {color: @@white;}. 而以这样进行变量的赋值:@white: @c ...
- jdk是什么?jdk1.8安装配置方法
jdk是什么呢?jdk的是java development kit的缩写,意思是java程序开发的工具包.也可以说jdk是java的sdk. 目前的JDK大致分三个大版本:Java SE:Java P ...
- hdu-2197 本原串---枚举因子+容斥定理
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2197 题目大意: 由0和1组成的串中,不能表示为由几个相同的较小的串连接成的串,称为本原串,有多少个 ...
- Redux概念简述
react可以写出一些比较简单的一些项目,但是只能写出很简单的一些项目,原因是什么呢,原因是react是一个非常轻量级的是视图层框架,打开官网可以看到大大的一行字,A JavaScript libra ...
- 课堂笔记--------JavaScript 的DOM操作
1.DOM的基本概念 DOM是文档对象模型,这种模型为树模型:文档是指标签文档:对象是指文档中每个元素:模型是指抽象化的东西. 2.Window对象操作 一.属性和方法: 属性(值或者子对象): op ...
- Array GCD CodeForces - 624D (dp,gcd)
大意: 给定序列, 给定常数a,b, 两种操作, (1)任选一个长为$t$的子区间删除(不能全部删除), 花费t*a. (2)任选$t$个元素+1/-1, 花费t*b. 求使整个序列gcd>1的 ...
- ubuntu应用商店打不开怎么办
依次运行下面的命令: 桥接网络设置好 sudo apt-get update sudo apt-get dist-upgrade sudo apt-get install --reinstall so ...
- 【JeeSite】角色分配
主要是(roleAssign.jsp , selectUserToRole.jsp )2个jsp页面的JS方法调用比较复杂,主页面要获取弹窗页面的数据 var pre_ids = h.find(&qu ...
- IntelliJ Idea 常用快捷键列表和快速输入
IntelliJ Idea 常用快捷键列表和快速输入 快速输入查看 最常用快捷键 Alt+Enter 万能快捷键,用于引入错误包 Ctrl+ Mouse left 快速调转定义 快捷键 Ctrl+Sh ...