CF1028C 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 nnrectangles 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.

The picture below shows the rectangles in the third and fourth samples.

题意:输出任意一个处于至少n-1个矩形相交区域的点
分析:考虑对于第i个矩形,如果不包括他,前面的i-1个矩形和后面的n-i个矩形是否可以有相交区域,如果有就一定有点处于其中,这个点也就位于n-1个矩形相交区域
我们可以在开始的时候求出前面i个矩形的相交区域pre[i]和后面i个矩形的相交区域pos[i],然后再遍历一次循环求当前矩形前面的矩形和后面矩形的相交区域pre[i-1]相交pos[i+1]
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 232674;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
const double pi = acos(-1.0);
struct node {
ll x1, y1, x2, y2;
};
node a[maxn], pre[maxn], pos[maxn];
int main() {
ll n;
cin >> n;
for( ll i = 1; i <= n; i ++ ) {
cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
}
node st = a[1], ed = a[n];
pre[0].x1 = -2e9, pre[0].y1 = -2e9, pre[0].x2 = 2e9, pre[0].y2 = 2e9;
pos[n+1].x1 = -2e9, pos[n+1].y1 = -2e9, pos[n+1].x2 = 2e9, pos[n+1].y2 = 2e9;
for( ll i = 1, j = n; i <= n; i ++, j -- ) {
st.x1 = max(st.x1,a[i].x1), st.y1 = max(st.y1,a[i].y1);
st.x2 = min(st.x2,a[i].x2), st.y2 = min(st.y2,a[i].y2);
pre[i] = st;
ed.x1 = max(ed.x1,a[j].x1), ed.y1 = max(ed.y1,a[j].y1);
ed.x2 = min(ed.x2,a[j].x2), ed.y2 = min(ed.y2,a[j].y2);
pos[j] = ed;
}
for( ll i = 1; i <= n; i ++ ) {
node t;
t.x1 = max(pre[i-1].x1,pos[i+1].x1), t.y1 = max(pre[i-1].y1,pos[i+1].y1);
t.x2 = min(pre[i-1].x2,pos[i+1].x2), t.y2 = min(pre[i-1].y2,pos[i+1].y2);
if( t.x2-t.x1 >= 0 && t.y2-t.y1 >= 0 ) {
cout << t.x1 << " " << t.y1 << endl;
break;
}
}
return 0;
}
CF1028C Rectangles 思维的更多相关文章
- AIM Tech Round 5C. Rectangles 思维
C. Rectangles time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- cf1028C. Rectangles(前缀和)
题意 给出$n$个矩形,找出一个点,使得至少在$n$个矩阵内 Sol 呵呵哒,昨天cf半夜场,一道全场切的题,我没做出来..不想找什么理由,不会做就是不会做.. 一个很显然的性质,如果存在一个点 / ...
- Codeforces | CF1028C 【Rectangles】
(这道题太简单啦...虽说我锤了一上午都没过...我能说这道题和\(CF1029C\)算是同一道题吗...) 按照时间顺序来说...\(CF1029\)在\(CF1028\)前面(而且\(CF1029 ...
- 【CF1028C】Rectangles(线段树)
题意: n<=1e5,abs(x[i]),abs(y[i]<=1e9 思路:这是正解 离散后线段树强打,数据结构越学越傻 #include<cstdio> #include&l ...
- codeforces 1028C Rectangles【思维】
题目:戳这里 题意:有n个矩阵,求一个点(保证存在)至少在n-1个点内. 解题思路:因为矩阵与坐标轴平行,所以我们画图可以发现如果存在点满足条件,则这些点中一定有一个是矩阵的顶点.我们可以把所有顶点的 ...
- 750. Number Of Corner Rectangles四周是点的矩形个数
[抄题]: Given a grid where each entry is only 0 or 1, find the number of corner rectangles. A corner r ...
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序
用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html 目录 马桶排序(令人 ...
- Photoshop、Illustrator思维导图笔记
半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.
- CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维
前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...
随机推荐
- Intellij IDEA 中 使用 Git
前一段时间使用 Microsoft 的 Visual Studio Code 中使用 Git 对前端项目进行项目代码的开发提交. 使用后感觉挺好的,用的多了也觉得挺简单方便的. 现在需要在 Intel ...
- 一看就懂的K近邻算法(KNN),K-D树,并实现手写数字识别!
1. 什么是KNN 1.1 KNN的通俗解释 何谓K近邻算法,即K-Nearest Neighbor algorithm,简称KNN算法,单从名字来猜想,可以简单粗暴的认为是:K个最近的邻居,当K=1 ...
- 派胜OA二次开发笔记(1)重写主界面
最近从派胜OA 2018 升级到 2019,为了二次开发方便,索性花了两天,反向分析 PaiOA 2019 主界面程序,重写大部分代码,方便对菜单权限进行控制. 主界面/core/index.aspx ...
- WPF:window设置单一开启
方法一: Window window = new Window();window.ShowDialog; 方法二: 设置一个判断窗口打开状态的全局控制变量 private bool i ...
- scrapy框架与python爬虫
- 浅谈osi模型 三次握手 四次挥手 ddos攻击原理
C/S B/S 架构 C:client 端 B:browser 浏览器 S:server 端 C/S架构,基于客户端与服务端之间的通信 例如:QQ,抖音,快手,微信,支付宝等等 优点:个性化设置,响应 ...
- 深入浅出Apriori关联分析算法(一)
在美国有这样一家奇怪的超市,它将啤酒与尿布这样两个奇怪的东西放在一起进行销售,并且最终让啤酒与尿布这两个看起来没有关联的东西的销量双双增加.这家超市的名字叫做沃尔玛. 你会不会觉得有些不可思议?虽然事 ...
- java NIO知多少
背景 Linux系统中的IO操作内部相当复杂,下面是一张带图片的LinuxIO相关层级关系: 下面是一个简化版本Linux内部IO层级图: 对此我的理解,java程序员版本的IO理解: java中的I ...
- Linux与Unix到底有什么不同?
来自:开源中国 原文:Linux vs. Unix: What's the difference? 链接: https://opensource.com/article/18/5/difference ...
- java学习二
一.类 1.类是模子,确定对象将会拥有的特征(属性)和行为(方法) 2.类的特点: (1).类是对象的类型 (2).具有相同属性和方法的一组对象的集合 3.类是抽象的概念,仅仅是模板,比如说:“手机” ...