Codeforces-527c
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm × h mm
sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.
In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly
made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments.
After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process.
Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree?
Input
The first line contains three integers w, h, n (2 ≤ w, h ≤ 200 000, 1 ≤ n ≤ 200 000).
Next n lines contain the descriptions of the cuts. Each description has the formH y or V x. In the first case Leonid makes the horizontal
cut at the distance ymillimeters (1 ≤ y ≤ h - 1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance x (1 ≤ x ≤ w - 1)
millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts.
Output
After each cut print on a single line the area of the maximum available glass fragment in mm2.
Example
4 3 4
H 2
V 2
V 3
V 1
8
4
4
2
7 6 5
H 4
V 3
V 5
H 2
V 1
28
16
12
6
4
Note
Picture for the first sample test:
Picture for the second sample test:
题解:可以用set和multiset来写; 用multiset来记录其分割后的长和宽,其中最大长和最大宽的乘积即为最大面积;
AC代码为:
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
#include<cstdio>
using namespace std;
set<int> Width;
set<int> High;
multiset<int> widths;
multiset<int> highs;
int main()
{
int w,h,n;
scanf("%d%d%d",&w,&h,&n);
Width.insert(0);
Width.insert(w);
High.insert(0);
High.insert(h);
widths.insert(w);
highs.insert(h);
for(int i=0; i<n; i++)
{
string o;
int x;
cin>>o>>x;
if(o[0]=='H')
{
High.insert(x);
int a=*(--High.find(x));
int b=*(++High.find(x));
highs.erase(highs.find(b-a));
highs.insert(x-a);
highs.insert(b-x);
}
else
{
Width.insert(x);
int a=*(--Width.find(x));
int b=*(++Width.find(x));
widths.erase(widths.find(b-a));
widths.insert(x-a);
widths.insert(b-x);
}
long long maxh=*(--highs.end());
long long maxw=*(--widths.end());
printf("%lld\n",maxh*maxw);
}
return 0;
}
Codeforces-527c的更多相关文章
- 【codeforces 527C】Glass Carving
[题目链接]:http://codeforces.com/contest/527/problem/C [题意] 让你切割一个长方形; 只能横切或竖切; 让你实时输出切完之后最大的长方形的面积; [题解 ...
- 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 ...
- Codeforces 527C Glass Carving
vjudge 上题目链接:Glass Carving 题目大意: 一块 w * h 的玻璃,对其进行 n 次切割,每次切割都是垂直或者水平的,输出每次切割后最大单块玻璃的面积: 用两个 set 存储每 ...
- Codeforces 527C Glass Carving(Set)
意甲冠军 片w*h玻璃 其n斯普利特倍 各事业部为垂直或水平 每个分割窗格区域的最大输出 用两个set存储每次分割的位置 就能够比較方便的把每次分割产生和消失的长宽存下来 每次分割后剩下 ...
- Codeforces - 527C 平衡树维护几何
题意:给定一个矩形\(W*H\),一共\(n\)次切割操作(水平/垂直),求每次操作后得出的最大面积 随机按tag扫CF题目找到的题,可以分别用平衡树维护割边的位置和长度(\(x/y\)各两个) 具体 ...
- Codeforces 527C Glass Carving (最长连续0变形+线段树)
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glas ...
- Glass Carving CodeForces - 527C (线段树)
C. Glass Carving time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
- 线段树详解 (原理,实现与应用)(转载自:http://blog.csdn.net/zearot/article/details/48299459)
原文地址:http://blog.csdn.net/zearot/article/details/48299459(如有侵权,请联系博主,立即删除.) 线段树详解 By 岩之痕 目录: 一:综述 ...
- codeforces #296 div2 (527C) STL中set的运用
题意:在一块H*M的玻璃上每次划一刀(仅仅能水平或竖直).输出每次划开之后剩下的玻璃中面积最大的一块的面积. 做题的时候.觉得这么大的数据量,有每次查询输出,应该是数据结构的内容. 这道题能够用STL ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- [LC]237题 Delete Node in a Linked List (删除链表中的节点)(链表)
①中文题目 请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点,你将只被给定要求被删除的节点. 现有一个链表 -- head = [4,5,1,9],它可以表示为: 示例 1: 输入: hea ...
- 【dp】Arrange the Schedule
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3538 题意:如题. 题解: 假如 一组数据 ...(n1)A.. ...
- static declaration follows non-static declaration
前段时间工作中要为android编译跨平台的第三方库,遇到了arc4random有关函数的“static declaration follows non-static declaration”问题,那 ...
- 用例图浅谈以及OOA再到情景分析的面向对象电梯的设计(慕课东北大学)面向对象设计思维模式
上班初期还不太适应,平时学习进度也跟不上,节奏慢下来会有时间更新的了. Diagram 这边以学生课程报名系统为例 这就是一种简单的用例图 用例图可以给读者提供的信息非常丰富,但是缺点是都是概 ...
- openresty如何完美替换nginx
下载openresty wget https://openresty.org/download/openresty-1.15.8.1.tar.gz tar zxvf openresty-1.15.8. ...
- 玩转网络(一)用TTL(Time To Live)排查网络问题
先大概介绍一下TTL(Time To Live)吧! TTL翻译过来就是网络生存时间,说的是一个网络数据包,它在网络设备中转发的跳数(网络设备这里一般指的是路由器),默认值为64,也有很多设置为了12 ...
- svn文件被锁不能提交的解决办法
记录工作中遇到的问题,分享出来: 前端时间在提交项目到svn遇到一个问题, 提交的时候提示:文件已经锁定!如下图: 原因是我之前提交的时候不小心中途停了,导致文件被锁,然后也没在意那么多, 趁着今天有 ...
- 使用RNN进行imdb影评情感识别--use RNN to sentiment analysis
原创帖子,转载请说明出处 一.RNN神经网络结构 RNN隐藏层神经元的连接方式和普通神经网路的连接方式有一个非常明显的区别,就是同一层的神经元的输出也成为了这一层神经元的输入.当然同一时刻的输出是不可 ...
- scala学习系列二
一 scala语言开发注意事项: 1 Scala程序的执行入口是main()函数 2 Scala语言严格区分大小写. 3 Scala方法由一条条语句构成,每个语句后不需要分号(Scala语言会在每行后 ...
- linux bash编程之函数和循环控制
函数:实现独立功能的代码段 函数只有在调用时才会执行 语法一: function F_NAME{ 函数体 } 语法二: F_NAME() { 函数体 } 函数的返回值: 默认函数返回值:函数执行状态返 ...