cf1028C. Rectangles(前缀和)
题意
给出$n$个矩形,找出一个点,使得至少在$n$个矩阵内
Sol
呵呵哒,昨天cf半夜场,一道全场切的题,我没做出来。。不想找什么理由,不会做就是不会做。。
一个很显然的性质,如果存在一个点 / 矩形在$n - 1$个矩形内的话
它们的交集不会是空集。
然后我们去枚举每个点,假设他不与$(n - 1)$个矩形相交,前缀和后缀和判一下就行
/* */
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
#define LL long long
#define rg register
#define sc(x) scanf("%d", &x);
#define pt(x) printf("%d ", x);
#define db(x) double x
#define rep(x) for(int i = 1; i <= x; i++)
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
char obuf[<<], *O = obuf;
#define OS *O++ = ' ';
using namespace std;
using namespace __gnu_pbds;
const int MAXN = 1e6 + , INF = 1e9 + , mod = 1e9 + ;
const double eps = 1e-;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N;
void print(int x) {
if(x > ) print(x / );
*O++ = x % + '';
}
struct Point {
int x1, y1, x2, y2;
Point operator + (const Point &rhs) const {
return (Point) {max(x1, rhs.x1), max(y1, rhs.y1), min(x2, rhs.x2), min(y2, rhs.y2)};
}
}P[MAXN], A[MAXN], B[MAXN];
main() {
N = read();
for(int i = ; i <= N; i++) {
P[i].x1 = read(); P[i].y1 = read();
P[i].x2 = read(); P[i].y2 = read();
}
A[] = P[]; for(int i = ; i <= N; i++) A[i] = A[i - ] + P[i];
B[N] = P[N]; for(int i = N - ; i >= ; i--) B[i] = B[i + ] + P[i];
for(int i = ; i <= N; i++) {
Point cur;
if(i == ) cur = B[];
else if(i == N) cur = A[N - ];
else cur = A[i - ] + B[i + ]; if(cur.x1 <= cur.x2 && cur.y1 <= cur.y2) {
printf("%d %d", cur.x1, cur.y1);
return ;
}
}
return ;
}
/* */
cf1028C. Rectangles(前缀和)的更多相关文章
- CF1028C Rectangles 思维
Rectangles time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #219 (Div. 2) D. Counting Rectangles is Fun 四维前缀和
D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes inpu ...
- Codeforces | CF1028C 【Rectangles】
(这道题太简单啦...虽说我锤了一上午都没过...我能说这道题和\(CF1029C\)算是同一道题吗...) 按照时间顺序来说...\(CF1029\)在\(CF1028\)前面(而且\(CF1029 ...
- 【CF1028C】Rectangles(线段树)
题意: n<=1e5,abs(x[i]),abs(y[i]<=1e9 思路:这是正解 离散后线段树强打,数据结构越学越傻 #include<cstdio> #include&l ...
- 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 5C. Rectangles 思维
C. Rectangles time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces 372B Counting Rectangles is Fun:dp套dp
题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问( ...
- HDU-6514 Monitor(二维前缀和+差分)
http://acm.hdu.edu.cn/showproblem.php?pid=6514 Problem Description Xiaoteng has a large area of land ...
- HDU1671——前缀树的一点感触
题目http://acm.hdu.edu.cn/showproblem.php?pid=1671 题目本身不难,一棵前缀树OK,但是前两次提交都没有成功. 第一次Memory Limit Exceed ...
随机推荐
- Microsoft visual studio关闭安全检查
在用Microsoft visual studio进行代码编写时,使用到列如sprintlf这种比较旧的指令,需要关闭Microsoft visual studio的安全检查: 设置预处理选项:a. ...
- mysql跨表更新示例
一.在同一个表中冗余存储记录之间的关系(组织机构树),查询时需要根据冗余字段进行关联查询 例如,下面的示例,用户表中有个字段friend标记其朋友关系,要求找出id=2及他的朋友(父节点) mysql ...
- Docker运行MongoDB及Redis及ssh端口映射远程连接
Docker运行MongoDB及Redis及ssh端口映射远程连接 本节内容简介 在本实验里我们将通过完成 MongoDB 和 Redis 两个容器来学习Dockerfile及Docker的运行机制. ...
- CS231n 2016 通关 第四章-NN 作业
cell 1 显示设置初始化 # A bit of setup import numpy as np import matplotlib.pyplot as plt from cs231n.class ...
- attachEvent与addEventListener的区别 真实例子
转自:https://www.cnblogs.com/Rosefxd/p/4921330.html 近日遇到attachEvent与addEventListener两个事件,哟,果断研究一下~~ 先普 ...
- Python学习资源汇总
Python 简明教程 (入门必看) * 在线浏览: http://woodpecker.org.cn/abyteofpython_cn/chinese/ Python Tutorial 简体中文版 ...
- CodeForces 1098F. Ж-function
题目简述:给定字符串$s[1 \dots n](n \leq 2 \times 10^5)$,以及$Q \leq 2 \times 10^5$个询问,每个询问有两个参数$1 \leq l \leq r ...
- dataTables使用ajax请求显示数据
dataTables是一种很好用前端表格显示库.当加载大量数据时,可以用Ajax 获取数据来提高效率,增速网页加载速率.下面以一个例子作示范. 首先,需要下载jQuery以及dataTables库.这 ...
- Flex AIR操作文件系统
1.各种文件操作http://blog.csdn.net/zdingxin/article/details/6635376 2.file.browseForDirectory("请选择一个目 ...
- 洛谷1087 FBI树 解题报告
洛谷1087 FBI树 本题地址:http://www.luogu.org/problem/show?pid=1087 题目描述 我们可以把由“0”和“1”组成的字符串分为三类:全“0”串称为B串,全 ...