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

曾经一直想让别人知道自己的心情,那些沉重,

Codeforces 528A Glass Carving STL模拟

相关文章:

你感兴趣的文章:

标签云: