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 ...
随机推荐
- requests 常见方法总结
请求设置:requests.get/post ( url, data={}, params={}, headers={}, timeout=0.01, files={} Session() ...
- 《Linux 进程间通信》命名管道:FIFO
命名管道的主要用途:不相关的进程之间交换数据. 命令行上创建命名管道: $ mkfifo filename 程序中创建命名管道: #include <sys/types.h> #incl ...
- Flex 远程视频监控观看端新版
第一个版本号仅仅做了预览这一块 http://blog.csdn.net/songanling/article/details/38306037,后面老板看了认为色调太暗.看得不舒服,然后就開始又一次 ...
- Woody的Python学习笔记4
Python模块 Import语句 想要使用Python源文件,仅仅须要在还有一个源文件中运行import语句.语法例如以下: import module1 当解释器遇到import语句.假设模块在当 ...
- Delphi的时间 x87 fpu control word 精度设置的不够
在win7 64位系统下, 一个DELPHI写的DLL注入一个C语言程序后. 出现非常奇怪的浮点数相加出错的情况. (注: 在XP系统下是正常的).比如: 40725.0001597563 + 0.7 ...
- [COI2007] [luogu P1823] Patrik 音乐会的等待 解题报告 (单调栈)
题目链接:https://www.luogu.org/problemnew/show/P1823 题目: N个人正在排队进入一个音乐会.人们等得很无聊,于是他们开始转来转去,想在队伍里寻找自己的熟人. ...
- Word frequency analysis
Write a program that reads a file, breaks each line into words, scripts whitespace and punctuation f ...
- java9新特性-3-JDK 和 JRE 的改变
1.JDK 与 JRE 的关系 JDK :JavaDevelopmentKit (Java开发工具包) JRE :JavaRuntimeEnvironment (Java运行环境) 说明: J ...
- PostgreSQL Replication之第三章 理解即时恢复(4)
3.4 重放事务日志 一旦我们创建了一个我们自己的初始基础备份,我们可以收集数据库创建的XLOG.当时间到时,我们可以使用所有这些XLOG 文件并执行我们所期望的恢复进程.这就像本节描述的一样工作. ...
- 十五 Canny边缘检测算法
一.Canny算法介绍 Canny 的目标是找到一个最优的边缘检测算法,最优边缘检测的含义是: 好的检测- 算法能够尽可能多地标识出图像中的实际边缘. 好的定位- 标识出的边缘要尽可能与实际图像中的实 ...