题目链接:点击打开链接

题意:

给定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模拟的更多相关文章

  1. Codeforces 527C Glass Carving

    vjudge 上题目链接:Glass Carving 题目大意: 一块 w * h 的玻璃,对其进行 n 次切割,每次切割都是垂直或者水平的,输出每次切割后最大单块玻璃的面积: 用两个 set 存储每 ...

  2. Codeforces 527C Glass Carving(Set)

    意甲冠军  片w*h玻璃  其n斯普利特倍  各事业部为垂直或水平  每个分割窗格区域的最大输出 用两个set存储每次分割的位置   就能够比較方便的把每次分割产生和消失的长宽存下来  每次分割后剩下 ...

  3. Codeforces 527C Glass Carving (最长连续0变形+线段树)

    Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glas ...

  4. CodeForces 527C. Glass Carving (SBT,线段树,set,最长连续0)

    原题地址:http://codeforces.com/problemset/problem/527/C Examples input H V V V output input H V V H V ou ...

  5. [codeforces 528]A. Glass Carving

    [codeforces 528]A. Glass Carving 试题描述 Leonid wants to become a glass carver (the person who creates ...

  6. Codeforces Round #296 (Div. 1) A. Glass Carving Set的妙用

    A. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  7. Codeforces Round #296 (Div. 2) C. Glass Carving [ set+multiset ]

    传送门 C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. codeforces 527 C Glass Carving

    Glass Carving time limit per test 2 seconds Leonid wants to become a glass carver (the person who cr ...

  9. Glass Carving CodeForces - 527C (线段树)

    C. Glass Carving time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...

随机推荐

  1. 【转载】CPU架构、指令集与指令集体系结构(ISA)

    最近学习计算机系统基础,了解到指令集体系结构. 对CPU架构.指令集和指令集体系结构的关系不清楚,特此记录. 指令集体系结构(ISA)包括 指令集.指令集编码.基本数据类型等. CPU架构 实现了 指 ...

  2. POJ 1821 Fence(单调队列优化DP)

    题解 以前做过很多单调队列优化DP的题. 这个题有一点不同是对于有的状态可以转移,有的状态不能转移. 然后一堆边界和注意点.导致写起来就很难受. 然后状态也比较难定义. dp[i][j]代表前i个人涂 ...

  3. react-native 编译报错: undefined is not an object (evaluating '_react2.PropTypes.func')

    情况通报: 因为是我的二维码模块报错,提示报错代码如下 重要信息是下面的红色字体部分(Android 模拟器红屏) undefined is not an object (evaluating '_r ...

  4. redhat7.5 升级OpenSSH_7.8p1

    1:拷贝编译好rpm安装包 [root@liwm ~]# scp -r root@192.168.31.130:/home/openssh7.8 /home/ root@192.168.31.130' ...

  5. Solr全文检索引擎配置及使用方法

    介绍 Solr是一款开源的全文检索引擎,基于lucene.拥有完善的可配置功能界面.具有丰富的查询语言,可扩展,可优化. 下载安装 进入solr官网下载包(这里我使用的版本是8.0) http://w ...

  6. mariadb 视图 事务 索引 外键

    视图 对于复杂的查询,在多个地方被使用,如果需求发生了改变,需要更改sql语句,则需要在多个地方进行修改,维护起来非常麻烦   假如因为某种需求,需要将user拆房表usera和表userb,该两张表 ...

  7. python基础5(文件操作,with语句)

    打开文件 #使用 open f = open('路径',mode = '打开模式', encoding='编码') #可以使用with语句打开,不需要关闭,可以同时打开多个文件 with open(' ...

  8. C#-反射知识点

    1.反射是基于Sytem.Type的,里面的很多方法是system.reflection里面的 MethodInfo[] tt= t.GetType().GetMethods(); //t是strin ...

  9. POJ——T 3687 Labeling Balls

    http://poj.org/problem?id=3687 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14842   ...

  10. windows环境利用apache 配置虚拟主机

    windows环境利用apache 配置虚拟主机 1.改动http.host #LoadModule vhost_alias_module modules/mod_vhost_alias.so #In ...