zoukankan      html  css  js  c++  java
  • Codeforces 528A Glass Carving STL模拟

    题目链接:点击打开链接

    题意:

    给定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 ", (ll)(*(--itx))*(*(--ity))); } return 0; }



  • 相关阅读:
    HDU3107 Godfather(树的重心)
    POJ1655 Balancing Act(树的重心)
    codeforces 691F Couple Cover(暴力预处理)
    codeforces 691E Xor-sequences(矩阵快速幂)
    codeforces 691D Swaps in Permutation(并查集)
    HDU5727 Necklace(环排+匈牙利)
    codeforces679C Bear and Square Grid(dfs优化)
    codeforces679B Bear and Tower of Cubes(思路)
    spring boot
    spring boot资料收集
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/7116802.html
Copyright © 2011-2022 走看看