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模拟的更多相关文章
- Codeforces 527C Glass Carving
vjudge 上题目链接:Glass Carving 题目大意: 一块 w * h 的玻璃,对其进行 n 次切割,每次切割都是垂直或者水平的,输出每次切割后最大单块玻璃的面积: 用两个 set 存储每 ...
- Codeforces 527C Glass Carving(Set)
意甲冠军 片w*h玻璃 其n斯普利特倍 各事业部为垂直或水平 每个分割窗格区域的最大输出 用两个set存储每次分割的位置 就能够比較方便的把每次分割产生和消失的长宽存下来 每次分割后剩下 ...
- Codeforces 527C Glass Carving (最长连续0变形+线段树)
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glas ...
- 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 ...
- [codeforces 528]A. Glass Carving
[codeforces 528]A. Glass Carving 试题描述 Leonid wants to become a glass carver (the person who creates ...
- 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 ...
- 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 ...
- codeforces 527 C Glass Carving
Glass Carving time limit per test 2 seconds Leonid wants to become a glass carver (the person who cr ...
- Glass Carving CodeForces - 527C (线段树)
C. Glass Carving time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
随机推荐
- 5、AFM(Attention+FM)-----Attentional Factorization Machines:Learning the Weight of Feature Interactions via Attention Network
1.摘要: 提出一个Attentional FM,Attention模型+因子分解机,其通过Attention学习到特征交叉的权重.因为很显然不是所有的二阶特征交互的重要性都是一样的,如何通过机器自动 ...
- 【BZOJ4444】国旗计划 - 决策单调性
Description A国正在开展一项伟大的计划——国旗计划.这项计划的内容是边防战士手举国旗环绕边境线奔袭一圈.这项计划需要多名边防战士以接力的形式共同完成,为此,国土安全局已经挑选了N名优秀的边 ...
- react-native 编译 undefined is not an object (evaluating '_react2.PropTypes.func')
情况通报: 因为是我的二维码模块报错,提示报错代码如下 重要信息是下面的红色字体部分(Android 模拟器红屏) undefined is not an object (evaluating '_r ...
- linux 连接 NAS
[root@kvm-server ~]# mount -o username=user01,password=1234567890 //192.168.31.20/share /mnt/nas Cou ...
- (QT)在命令行编译ui文件和程序
1.新建helloworld_2文件夹,将helloworld里的main.cpp和hellodialog.cpp两个文件复制过来. 2.打开控制台.此时不能用cmd,否则不能出最后的结果(lz在运行 ...
- 紫书 习题 11-4 UVa 1660 (网络流拆点法)
这道题改了两天-- 因为这道题和节点有关, 所以就用拆点法解决节点的容量问题. 节点拆成两个点, 连一条弧容量为1, 表示只能经过一次. 然后图中的弧容量无限. 然后求最小割, 即最大流, 即为答案. ...
- [Typescript] Promise based delay function using async / await
Learn how to write a promise based delay function and then use it in async await to see how much it ...
- php通过shell调用Hadoop的方法
1.php代码(index.php) <!DOCTYPE html> <html> <!-- <style> body{background-color:re ...
- IOS音频架构之Audio Unit
在前面的章节部分我们已经对IOS音频结构有了一个清晰的认识,知道Audio Unit是位于整个音频结构的最底层,这一层非常多API已经開始和硬件打交道了.所以比較复杂,有了前面的基础再来看这个部分就比 ...
- AVEVA PDMS to DIALux
AVEVA PDMS to DIALux eryar@163.com Abstract. DIAL develops DIALux - the world's leading software f ...