Codeforces 528A Glass Carving STL模拟

38 篇文章 0 订阅
24 篇文章 0 订阅

题目链接:点击打开链接

题意:

给定n*m的矩阵,k个操作

2种操作:

1、H x 横向在x位置切一刀

2、V y 竖直在y位置切一刀

每次操作后输出最大的矩阵面积

思路:

因为行列是不相干的,所以只要知道每次操作后行的最大间距和列的最大间距,相乘就是最大面积

用一个set维护横向的所有坐标点,一个multiset维护横向的间距。

每次对行操作x则在set中找到比x大的最小数 r 和比x小的最大数l ,操作前的间距dis = r-l,在multiset中删除dis并插入r-x 和x-l。再在set中插入x

对列操作同理。

操作完后取行列各自的最大间距相乘即可,注意相乘可能爆int

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;
const int N = 105;

int heheeh;
template <class T>
inline bool rd(T &ret) {
    char c; int sgn;
    if (c = getchar(), c == EOF) return 0;
    while (c != '-' && (c<'0' || c>'9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}
template <class T>
inline void pt(T x) {
    if (x <0) {
        putchar('-');
        x = -x;
    }
    if (x>9) pt(x / 10);
    putchar(x % 10 + '0');
}
struct node {
    int l, r, len;

};
multiset<int> h, c;
set<int> hh, cc;
set<int>::iterator it;
multiset<int>::iterator itx, ity;
int main() {
    int n, m, k, x;
    char a[5];
    scanf("%d%d%d", &m, &n, &k);

    hh.insert(0); hh.insert(m);
    h.insert(m);
    cc.insert(0); cc.insert(n);
    c.insert(n);
    while (k-- > 0) {
        scanf("%s %d", a, &x);
            if (a[0] == 'H') {
            it = cc.upper_bound(x);
            int r = *it; int l = *(--it);
            c.erase(c.lower_bound(r - l));
            c.insert(r - x);
            c.insert(x - l);
            cc.insert(x);
        }
        else {
            it = hh.upper_bound(x);
            int r = *it; int l = *(--it);
            h.erase(h.lower_bound(r - l));
            h.insert(r - x);
            h.insert(x - l);
            hh.insert(x);
        }
        itx = h.end();
        ity = c.end();
        printf("%I64d\n", (ll)(*(--itx))*(*(--ity)));
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值