Codeforces 527C Glass Carving
vjudge 上题目链接:Glass Carving
题目大意: 一块 w * h 的玻璃,对其进行 n 次切割,每次切割都是垂直或者水平的,输出每次切割后最大单块玻璃的面积:

用两个 set 存储每次切割的位置,就可以比较方便的把每次切割产生和消失的长宽存下来(用个 hash 映射数组记录下对应值的长宽的数量即可,O(1) 时间维护),每次切割后剩下的最大长宽的积就是答案了:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
typedef long long LL;
const int N = ; int w[N], h[N]; // 记录存在的边长的数量
set<int> sw, sh; // 记录下所有切点的位置
set<int>::iterator i,j; void insert(set<int> &s, int *b, int p) {
s.insert(p);
i = j = s.find(p);
++j; --i;
--b[*j - *i]; // 除掉被分开的长宽
++b[p - *i]; // 新产生了两个长宽
++b[*j - p];
} int main() {
int ww,hh,n,p;
while(~scanf("%d %d %d",&ww,&hh,&n)) {
sw.clear(); sh.clear();
sw.insert(); sw.insert(ww);
sh.insert(); sh.insert(hh); memset(w, , sizeof w); w[ww]++;
memset(h, , sizeof h); h[hh]++;
int y = ww, x = hh; while(n--) {
getchar();
if(getchar() == 'H') {
scanf("%d",&p);
insert(sh, h, p);
}
else {
scanf("%d",&p);
insert(sw, w, p);
}
while(!w[y]) --y; // 因为每次切割后最大值总是单调递减的,所以这样维护即可,如果从头到尾扫一遍的话会超时的
while(!h[x]) --x;
printf("%I64d\n", (LL)x * y);
}
}
return ;
}
参考了别人的思路才会做的,果然好强大,自己也好弱 Orz 。。。
Codeforces 527C Glass Carving的更多相关文章
- 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 527C Glass Carving
数据结构维护二维平面 首先横着切与竖着切是完全没有关联的, 简单贪心,最大子矩阵的面积一定是最大长*最大宽 此处有三种做法 1.用set来维护,每次插入操作寻找这个点的前驱和后继,并维护一个计数数组, ...
- Codeforces 528A Glass Carving STL模拟
题目链接:点击打开链接 题意: 给定n*m的矩阵.k个操作 2种操作: 1.H x 横向在x位置切一刀 2.V y 竖直在y位置切一刀 每次操作后输出最大的矩阵面积 思路: 由于行列是不相干的,所以仅 ...
- 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 ...
- Codeforces Round #296 (Div. 1) A. Glass Carving Set的妙用
A. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #296 (Div. 2) C. Glass Carving [ set+multiset ]
传送门 C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- Python 深拷贝和浅拷贝
Python中,对象的赋值,拷贝(深/浅拷贝)之间是有差异的,如果使用的时候不注意,就可能产生意外的结果. 下面本文就通过简单的例子介绍一下这些概念之间的差别. 对象赋值 直接看一段代码: will= ...
- SQL数据类型大全 《转自网络》
数据类型是数据的一种属性,表示数据所表示信息的类型.任何一种计算机语言都定义了自己的数据类型.当然,不同的程序语言都具有不同的特点,所定义的数据类型的种类和名称都或多或少有些不同.SQLServer ...
- 【转】启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法! .
转载地址:http://blog.csdn.net/zyz511919766/article/details/7442633 原因1:给定目录下jvm.dll不存在. 对策:(1)重新安装jre或者j ...
- HttpClient的使用方法
使用httpClient发送请求.接收响应很简单.一般需要以下几个步骤. 第一:创建HttpClient对象: 第二:创建请求方法的实例,并指定请求URL.如果要发送GET请求,创建HttpGet对象 ...
- CSS选择器及其优先级
一:一些普通的选择器 <!DOCTYPE html> <html> <head lang="en"> <meta charset=&quo ...
- vi编辑文件E437: terminal capability "cm" required 解决办法
E437: terminal capability "cm" required 这个错误一般是环境变量TERM没有配置或者配置错误所致. 解决办法: 执行export TERM=x ...
- Python学习笔记-Day2-Python基础之元组操作
元组的常用操作包括但不限于以下操作: 元组的索引,计数等 这里将对列表的内置操作方法进行总结归纳,重点是以示例的方式进行展示. 使用type获取创建对象的类 type(tuple) 使用dir获取类的 ...
- E: Sub-process /usr/bin/dpkg returned an error code (1) 解决方案
转载自:http://www.cnblogs.com/eddy-he/archive/2012/06/20/2555918.html cd /var/lib/dpkg sudo mv info inf ...
- selenium帮助手册以及 webdriver的各种driver
帮助手册 http://selenium-python.readthedocs.io/locating-elements.html 转载于:http://blog.csdn.net/five3/art ...
- phpcms 04
首页index.html 首页头条推荐 <div class="col-left"> <div class="news-hot"> &l ...