CF 527C Glass Carving
数据结构维护二维平面
首先横着切与竖着切是完全没有关联的,
简单贪心,最大子矩阵的面积一定是最大长*最大宽
此处有三种做法
1.用set来维护,每次插入操作寻找这个点的前驱和后继,并维护一个计数数组,来维护最大值
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
const int MAXN = 400005;
int init() {
int rv = 0, fh = 1;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') fh = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
rv = (rv<<1) + (rv<<3) + c - '0';
c = getchar();
}
return fh * rv;
}
int w, h, n, maw, mah, cnt1[MAXN], cnt2[MAXN];
set <int> s1, s2;
set <int> :: iterator u, v;
int main() {
freopen("in.txt", "r", stdin);
w = init(); h = init(); n = init();
mah = h; maw = w;
cnt1[mah]++; cnt2[maw]++;
s1.insert(h);s2.insert(0);s2.insert(w);s1.insert(0); //要提前把这两个点加上
for(int i = 1 ; i <= n ; i++) {
char c;
scanf(" %c ", &c);
int t = init();
if(c == 'H'){
s1.insert(t);
u = v =s1.find(t);
u--; v++;
cnt1[*v - *u]--;
cnt1[*v - t]++; cnt1[t - *u]++;
while(!cnt1[mah]) mah--; //此处因为mah是不增的,所以这个操作的总复杂度是O(h)
}else {
s2.insert(t);
u = v =s2.find(t);
u--; v++;
cnt2[*v - *u]--;
cnt2[*v - t]++; cnt2[t - *u]++;
while(!cnt2[maw]) maw--;
}
printf("%lld\n", (long long)maw * mah);
}
fclose(stdin);
return 0;
}
平衡树,与set类似
线段树,用 \(01\) 序列表示某条边哪里被切割,本题就变成了维护最长连续0
区间需要维护: 区间左右开始连续0的长度, 区间最长连续0的长度, 区间是否全为0
CF 527C Glass Carving的更多相关文章
- Codeforces 527C Glass Carving
vjudge 上题目链接:Glass Carving 题目大意: 一块 w * h 的玻璃,对其进行 n 次切割,每次切割都是垂直或者水平的,输出每次切割后最大单块玻璃的面积: 用两个 set 存储每 ...
- Codeforces 527C Glass Carving(Set)
意甲冠军 片w*h玻璃 其n斯普利特倍 各事业部为垂直或水平 每个分割窗格区域的最大输出 用两个set存储每次分割的位置 就能够比較方便的把每次分割产生和消失的长宽存下来 每次分割后剩下 ...
- Codeforces 527C Glass Carving (最长连续0变形+线段树)
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glas ...
- CodeForces 527C. Glass Carving (SBT,线段树,set,最长连续0)
原题地址:http://codeforces.com/problemset/problem/527/C Examples input H V V V output input H V V H V ou ...
- CF #296 (Div. 1) A. Glass Carving 线段树
A. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- C. Glass Carving (CF Round #296 (Div. 2) STL--set的运用 && 并查集方法)
C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- CF # 296 C Glass Carving (并查集 或者 multiset)
C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Glass Carving CodeForces - 527C (线段树)
C. Glass Carving time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
- [codeforces 528]A. Glass Carving
[codeforces 528]A. Glass Carving 试题描述 Leonid wants to become a glass carver (the person who creates ...
随机推荐
- Xamarin.IOS binding库编译失败的解决办法
报错:目标框架 Xamarin.iOS,Version=v1.0 未找到 复制 C:\Program Files (x86)\Microsoft Visual Studio\2017\Professi ...
- 欧拉回路/通路 Codeforces Round #288 (Div. 2)
http://codeforces.com/contest/508/problem/D 以上是题目链接 题目大意 给n个字符串看能不能链接在一起 因为 三个三个分割 所以字符串 如abc ab作为起点 ...
- 编程中什么是「Context(上下文)」?
https://www.zhihu.com/question/26387327 每一段程序都有很多外部变量.只有像Add这种简单的函数才是没有外部变量的.一旦你的一段程序有了外部变量,这段程序就不完整 ...
- Python 基础-3
使用while打印1 2 3 4 5 6 8 9 10 count = 0 #while count < 10: while count < 10: count += 1 if co ...
- 【转载】K-mer算法
k-mer是指将reads分成包含k个碱基的字符串,一般长短为m的reads可以分成m-k+1个k-mers.举个例子吧,为了简化,有这么个reads(当然实际比这个长):AACTGACTGA.如果k ...
- Hibernate 多表查询 - Criteria添加子字段查询条件 - 出错问题解决
Criteria 查询条件如果是子对象中的非主键字段会报 could not resolve property private Criteria getCriteria(Favorite favori ...
- Bootstrap历练实例:基本按钮群组
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- JS面试题--使用for循环打印1-10,每个数字出现的间隔约500ms
又来刷面试题啦,哈哈. 要求:使用for循环打印1-10,每个数字出现的间隔约500ms. 分析:考察点--闭包,块级作用域 方式一.使用闭包+立即执行函数,自己当时的思路也是这样想的,但是,结果却没 ...
- Java输入几行字符串
查找书籍 给定n本书的名称和定价,本题要求编写程序,查找并输出其中定价最高和最低的书的名称和定价. 输入格式: 输入第一行给出正整数n(<10),随后给出n本书的信息.每本书在一行中给出书名,即 ...
- hosts设置本地虚拟域名
C:\Windows\System32\drivers\etc hosts 需要用管理员运行