Codeforces 528A Glass Carving STL類比

來源:互聯網
上載者:User

標籤:

題目連結:點擊開啟連結

題意:

給定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;}


Codeforces 528A Glass Carving STL類比

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.