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 ...
随机推荐
- Android计算器简单逻辑实现
Android计算器简单逻辑实现 引言: 我的android计算器的实现方式是:按钮输入一次,就处理一次. 但是如果你学过数据结构(栈),就可以使用表达式解析(前缀,后缀)处理. 而这个方式已经很成熟 ...
- 2018 北京区域赛 I - Palindromes (找规律)
题目 HihoCoder - 1878 题目大意 给出k,让求出第k个回文数(k的“长度”不超过1e5) 题解 之前做过类似的题,是统计各阶段的数找到第K个回文数,但这里K太大,需要寻找新的方法. 打 ...
- 在Terminal中,如何打开Finder,并显示当前的目录
这是一个非常方便实用的小技巧,在Terminal中输入如下命令: $ open . 有图有真相: 参考: Open Finder in Current Folder from Terminal
- HTML 显示和隐藏浏览器滚动条
滚动条和overflow有关 显示: overflow-x:auto; overflow-y:auto; overflow-x:scroll; overflow-y:scroll; 隐藏: overf ...
- JS面试题--使用for循环打印1-10,每个数字出现的间隔约500ms
又来刷面试题啦,哈哈. 要求:使用for循环打印1-10,每个数字出现的间隔约500ms. 分析:考察点--闭包,块级作用域 方式一.使用闭包+立即执行函数,自己当时的思路也是这样想的,但是,结果却没 ...
- 【模拟】bzoj1686: [Usaco2005 Open]Waves 波纹
打完模拟题来庆祝一波:):感觉最近陷入一种“口胡五分钟打题两小时”的巨坑之中…… Description Input 第1行:四个用空格隔开的整数Pj Bi,B2,R. P(1≤P≤5)表示石 ...
- django第8天(在测试文件中运行django项目|单表操作)
django第8天 在测试文件中运行django项目 1.将项目配置文件数据库该为mysql,修改配置信息 PORT = '127.0.0.1' DATABASES = { 'default': { ...
- DFS:POJ1562-Oil Deposits(求连通块个数)
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Description The GeoSurvComp geologic survey com ...
- 洛谷P3961 图的遍历
题目来源 做这道题的方法不少. 在这里我只提一种 就是大法师. 可以采用反向建边,从最大的点开始dfs 我们考虑每次从所剩点中最大的一个点出发,我们暂且称它为i,而凡是i这个点所能到达的点,可以到达的 ...
- Java-替换字符串中的子字符串
自顶一个repace方法 package com.tj; public class MyClass implements Cloneable { public static void main(Str ...