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; }
转载于:https://www.cnblogs.com/liguangsunls/p/7116802.html
Codeforces 528A Glass Carving STL模拟相关推荐
- Codeforces 527C Glass Carving
vjudge 上题目链接:Glass Carving 题目大意: 一块 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 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 ...
- C++ STL : 模拟实现STL中的关联式容器unordered_map/unordered_set
目录 unordered_map/unordered_set unordered_map/unordered_set与map/set的区别 底层哈希桶的改造 仿函数 Key值的获取方法 hash(ke ...
- CodeForces 1463 C. Busy Robot 模拟
CodeForces 1463 C. Busy Robot 模拟 题目大意: 有一个一维坐标轴,在最初时刻有个机器人位于坐标 0 0 0 位置,有 n n n 个命令,对于每一个命令在 t i t_i ...
- 1/22 测试一(STL 模拟 贪心)C.(贪心,给出气球,输出最好成绩)Contest Balloons
1/22 测试一(STL 模拟 贪心) C.(贪心,给出气球,输出最好成绩)Contest Balloons One tradition of ACM-ICPC contests is that a ...
- 【CodeForces - 527C】Glass Carving(线段树或者SBT或者set)
题干: Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the ...
- Codeforces Round #552 (Div. 3) E stl模拟 F dp G gcd
contest链接 https://codeforces.com/contest/1154 E 题解思路 直接哈希模拟删除T了,可以用setsetset和lowerlowerlower_boundbo ...
- CF--思维练习--CodeForces - 220C Little Elephant and Shifts (STL模拟)
ACM思维题训练集合 The Little Elephant has two permutations a and b of length n, consisting of numbers from ...
最新文章
- IT运维真需为“邮筒”做提前保护吗?
- PHP+XML留言板
- java安装_我最喜欢的Java高级开发人员书籍
- SAP Commerce Cloud(原Hybris) impex 里的美元(dollar $)符号
- 移动web性能优化笔记
- CentOs中iptables配置允许mysql远程访问
- LeetCode 129. 求根到叶子节点数字之和(DFS)
- 手机学linux软件下载,Linux标准教科书下载
- 命令行开发、编译、打包Android应用程序
- 天池学习赛:工业蒸汽量预测4——模型验证
- JAVA调用NuSoap服务
- livevent的几个问题
- php 未找到驱动程序,Laravel 5 PDOException找不到驱动程序
- 电教室软件 linux,在深度操作系统上安装多媒体电子教室Veyon
- phpwind服务搭建
- cadz轴归零命令_cadz轴归零(cad全部z轴归零)
- python处理页眉_【python-docx 05】操作页眉和页脚
- 给南京沁恒芯片公司点个赞
- 虚拟化技术加速Android模拟器尝试
- vaex库使用方法python_Python秒开100G数据是怎么办到的?
热门文章
- linux下配置Java和Go环境
- 修改placeorder html,数字分发Web服务DDWSPlaceOrder-服务手册-Partner.PDF
- 易语言 网页用什么编码_Plessey条码用的什么编码方式?
- 作为研发工程师,不可不知的运维技能武器库,这些你知道吗
- 南大计算机系尹一通,南京大学计算机科学与技术系导师教师师资介绍简介-尹一通(博导)...
- php 环状,CSS3能写出这种环状吗,不是环形进度条?
- java applet html_将图像从Java Applet传递到HTML
- 一个类的java代码_求一段java代码,定义一个类
- webbrowser加载地图网页出现脚本错误解决
- Currency Exchange