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 ...
随机推荐
- Oracle日志组添加冗余文件和日志组
rac中需要指定thread添加日志组RAC:alter database add logfile thread 1 group 1('+DATA/irac/redo01_1.log','+DATA/ ...
- GitLab 数据备份和恢复
GitLab 备份 /opt/gitlab/bin/gitlab-rake gitlab:backup:create //只是备份各项目的数据 完成后会在默认路径下多出来备份的tar包! /var/o ...
- python中的 if __name__ == “__main__”: 有什么用
https://stackoverflow.com/questions/419163/what-does-if-name-main-do# 问题: What does if name == " ...
- groupadd
功能说明:用于创建新的用户组. 参数选项:-g gid 指定用户组的gid,除非接-o参数,否则ID值唯一且不为负,如果不指定-g参数,则gid从500开始.-f 新增一个账户,强制覆盖一个已存在的组 ...
- vim编辑下几个退出保存的命令
:w 将数据写入硬盘 :w! 若文件属性为“只读”时,强制写入该文件.不过需要注意,这个是在你的权限可以改变的情况下才能成立 :q 离开vim :q! 修改过文件,又不想保存 :wq 保存后离开 :w ...
- bootstrap-multiselect.js多选下拉框初始化时默认选中初始值
bootstrap-multiselect.js多选下拉框默认值设置 一.案例数据格式 二.HTML代码 <select id="msgRoles" multiple=&q ...
- Android(java)学习笔记37:String类型的面试题
1. String类型面试题: package cn.itcast_02; /* * String s = new String(“hello”)和String s = “hello”;的区别? * ...
- 【BZOJ2510】弱题
题目大意 有\(M\)个球,一开始每个球均有一个初始标号,标号范围为\(1-N\)且为整数,标号为i的球有\(a_i\)个,并保证\(\sum a_i=M\). 每次操作等概率取出一个球(即取出每个球 ...
- TSP 模拟退火
TSP——模拟退火解法 都知道TSP是经典的NP问题,从一个点开始遍历所有点,不重复,求最短路径. 可以用枚举终点,跑流量为2的最小费用,图论来做,时间复杂度为 费用流已经用到堆优化了.显然点,边 ...
- Ajax实现异步操作实例_针对JSON格式的请求数据
最近写了一篇ajax异步操作XML格式的,今天就写关于json格式的. 一.简单了解Json 1. JSON有两种表示结构,对象和数组. 1.1 对象: { key1:value1, key2:val ...