码迷,mamicode.com
首页 > 其他好文 > 详细

C. Glass Carving (CF Round #296 (Div. 2) STL--set的运用)

时间:2015-03-18 18:05:12      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:glass carving   cf round #296 div. 2   

C. Glass Carving
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular wmm ?×? 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?0001?≤?n?≤?200?000).

Next n lines contain the descriptions of the cuts. Each description has the form H y or V x. In the first case Leonid makes the horizontal cut at the distance y millimeters (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.

Sample test(s)
input
4 3 4
H 2
V 2
V 3
V 1
output
8
4
4
2
input
7 6 5
H 4
V 3
V 5
H 2
V 1
output
28
16
12
6
4
Note

Picture for the first sample test:

技术分享
Picture for the second sample test:
技术分享

题意:一个w*h的玻璃,现在水平或竖直切n次(“H”表示水平切,“V”表示竖直切),每一次切后输出当前切成的块中的最大面积。

思路:用set记录切割的位置(要用两个set,分别来记录长和宽),multiset记录某一条边被切后 所得到的 小段的长度(也要两个,分别记录长和宽的)。那么每次切后就从multiset中取出最大的长和宽,相乘即得面积。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define FRE(i,a,b)  for(i = a; i <= b; i++)
#define FRL(i,a,b)  for(i = a; i < b; i++)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define DBG         pf("Hi\n")
typedef __int64 ll;
using namespace std;

int w,h,n;
set<int>wxs;
set<int>hxs;
multiset<int>wds;
multiset<int>hds;

int main()
{
    int i,j;
    while (~sfff(w,h,n))
    {
        set<int>::iterator it,p;
        char s[3];
        int x;
        wxs.clear();
        hxs.clear();
        wds.clear();
        hds.clear();
        wxs.insert(0); wxs.insert(w);
        hxs.insert(0); hxs.insert(h);
        wds.insert(w); hds.insert(h);
        while (n--)
        {
            scanf("%s%d",s,&x);
            if (s[0]=='H')
            {
                it=hxs.lower_bound(x);
                p=it;
                p--;
                int dis = *it - *p;
                hds.erase(hds.find(dis));
                hds.insert(*it-x);
                hds.insert(x-*p);
                hxs.insert(x);
            }
            else
            {
                it=wxs.lower_bound(x);
                p=it;
                p--;
                int dis = *it - *p;
                wds.erase(wds.find(dis));
                wds.insert(*it-x);
                wds.insert(x-*p);
                wxs.insert(x);
            }
            int xx= *wds.rbegin();
            int yy= *hds.rbegin();
            pf("%I64d\n",(ll)xx * (ll)yy);  //最后要强制转化,不然会爆int
        }
    }
    return 0;
}



C. Glass Carving (CF Round #296 (Div. 2) STL--set的运用)

标签:glass carving   cf round #296 div. 2   

原文地址:http://blog.csdn.net/u014422052/article/details/44415443

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!