Codeforces Round #296 (Div. 2) - C. Glass Carving(STL)

题目:

http://codeforces.com/contest/527/problem/C

题意:

求出在一个w, h (2 ≤ w, h ≤ 200 000)矩形中进行n(1 ≤ n ≤ 200 000)次横切或竖切操作之后得到的最大面积的矩阵.

思路:

set大法.

multiset<int> H, W, nh, nv;
nh :记录每一次横切操作; nw: 记录每一次竖切操作.

H:记录得到的横边; W:记录得到的竖边.

 H.erase(H.find(*n2 - *n1)); 此操作很好的降低了时间复杂度:)
AC.

#include <iostream>
#include <cstdio>
#include <set>
#include <algorithm>
#include <cstring>

using namespace std;
int w, h, n;
multiset<int> H, W, nh, nv;

void init()
{
    H.clear(); W.clear();
    H.insert(h);
    W.insert(w);
    nh.clear(); nv.clear();
    nh.insert(0); nv.insert(0);
    nh.insert(h); nv.insert(w);
}
int main()
{
//freopen("in", "r", stdin);
    while(~scanf("%d %d %d", &w, &h, &n)) {
        int a, ans1, ans2;
        char s[2];
        init();

        multiset<int>::iterator n1, n2;

        while(n--) {
            getchar();
            scanf("%s%d", s, &a);
            if(s[0] == 'H') {
                n2 = nh.upper_bound(a);
                n1 = (--n2);
                n2++;

                H.erase(H.find(*n2 - *n1));
                H.insert(*n2 - a);
                H.insert(a - *n1);

                ans1 = *(--H.end()); ans2 = *(--W.end());
                printf("%I64d\n", 1LL*ans1*ans2);
                nh.insert(a);

            }
            if(s[0] == 'V') {
                n2 = nv.upper_bound(a);
                n1 = (--n2);
                n2++;

                W.erase(W.find(*n2 - *n1));
                W.insert(*n2 - a);
                W.insert(a - *n1);

                ans1 = *(--H.end()); ans2 = *(--W.end());
                printf("%I64d\n", 1LL*ans1*ans2);
                nv.insert(a);
            }
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值