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 ...
随机推荐
- 工艺(SAM)
传送门 用SAM可以非常轻松的解决问题. 只要把原串向SAM中插入两次,之后直接从\(t_0\)状态开始每次贪心跑最小就可以了. 因为这个题要用map,所以之前取begin即可. // luogu-j ...
- LearnToRank
1 概述 RankNet.LambdaRank和LambdaMART是三个关系非常紧密的机器学习排序算法.简而言之,RankNet是最基础,基于神经网络的排序算法:而LambdaRank在RankNe ...
- 使用 Git 命令去管理项目的版本控制(一)
参考资料:参考 参考 声明本文是作者原创,是自己的学习笔记,仅供学习参考. 在 10.11.2Mac系统中,要显示隐藏的文件夹使用命令行: defaults write com.apple.find ...
- Hadoop2 使用 YARN 运行 MapReduce 的过程源码分析
Hadoop 使用 YARN 运行 MapReduce 的过程如下图所示: 总共分为11步. 这里以 WordCount 为例, 我们在客户端终端提交作业: # 把本地的 /home/hadoop/t ...
- mysql 快捷键
1.ctrl+q 打开查询窗口2.ctrl+/ 注释sql语句3.ctrl+shift +/ 解除注释4.ctrl+r 运行查询窗口的s ...
- tcp/ip详解(转)
与UDP不同的是,TCP提供了一种面向连接的.可靠的字节流服务.TCP协议的可靠性主要有以下几点保障: (1)应用数据分割成TCP认为最适合发送的数据块.这部分是通过“MSS”(最大数据包长度)选项来 ...
- java集合框架之聚合操作stream
参考http://how2j.cn/k/collection/collection-aggregate/702.html#nowhere 聚合操作 JDK8之后,引入了对集合的聚合操作,可以非常容易的 ...
- TypeScript完全解读(26课时)_13.TypeScript完全解读-高级类型(2)
13.TypeScript完全解读-高级类型(2) 高级类型中文网的地址:https://typescript.bootcss.com/advanced-types.html 创建文件并在index. ...
- 常用的网站站长SEO工具
网站管理员工具 网站管理员工具需要对网站域名所有权进行验证,通常是通过上传指定文件.增加META或者修改网站DNS来验证管理员身份,通过验证后,网站管理员可以查询到自己网站的各类统计信息. 1. Go ...
- 面试lua笔试题各种坑
替换字符串"abcdefgh" 中的"abc"为"ddc" local str ="abcdefgh"; b = str ...