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 ...
随机推荐
- NTP客户端的设置
LINUX做为客户端自动同步时间 如果想定时进行时间校准,可以使用crond服务来定时执行. 编辑 /etc/crontab 文件 加入下面一行: 30 8 * * * root /usr/sbi ...
- c#之线程池
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- Cookie案例
实现的功能是:在页面上点击,各种书名,跳转到另一个页面,在点解return 回到原来的页面,并且最下面出现刚才点击的书名:进行多次操作,都会出现刚刚点击的书名: 类似于:在浏览器上显示你登录的记录: ...
- Python学习笔记-Day3-python内置函数
python内置函数 1.abs 求绝对值 2.all 判断迭代器中的所有数据是否都为true 如果可迭代的数据的所有数据都为true或可迭代的数据为空,返回True.否则返回False 3.a ...
- Linux文件描述符与打开文件之间的区别(转载)
转载请说明出处:http://blog.csdn.net/cywosp/article/details/38965239 1. 概述 在Linux系统中一切皆可以看成是文件,文件又可分为: ...
- IoC容器概述
IoC(Inverse of Control: 控制反转)是spring容器的内核, 字面意思是: 控制反转, 包含两个内容:(1) 控制, (2) 反转.那到底是什么东西的控制被反转了呢? 对于软件 ...
- AfterEffects 关键帧辅助功能
http://www.cocoachina.com/design/20160121/15073.html 标准缓动曲线查询网址:http://easings.net/zh-cn
- sqlitehelper封装
appsettings <configuration> <appSettings> <add key="ConnectionString&q ...
- 为什么需要main函数,及其参数的用法
首先,需要明确main函数是什么? 答:main函数是C语言约定的入口函数 C99标准里面是这样描述的: Program startup The function called at program ...
- VC如何让窗口半透明
转载:http://blog.csdn.net/bichenggui/article/details/8291946 //加入WS_EX_LAYERED扩展属性 LONG styleValue = : ...