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 ...
随机推荐
- 路飞学城Python-Day7(practise)
# 1.编码问题# i.请说明python2与python3中的默认编码是什么?# python2中的默认编码是ASCII码,只能识别英文等其他字符# python3中的默认编码是utf-8# ii. ...
- POJ 2228 Naptime(DP+环形处理)
题解 这题一眼望去DP. 发现自己太智障了. 这题想的是O(n^3m)的. 环形处理只会断环成链....然后DP也想的不好. 我们先考虑如果除去环这题该怎么做? dp[i][j][0/1]代表到第i小 ...
- [APIO2014]回文串(回文自动机)
题意 给你一个由小写拉丁字母组成的字符串 s.我们定义 s 的一个子串的存在值为这个子串在 s 中出现的次数乘以这个子串的长度. 对于给你的这个字符串 s,求所有回文子串中的最大存在值. |S|< ...
- python yield 生成器的介绍(转载)
您可能听说过,带有 yield 的函数在 Python 中被称之为 generator(生成器),何谓 generator ? 我们先抛开 generator,以一个常见的编程题目来展示 yield ...
- TODOList 多线程交互、RCP、事物控制、数据倾斜、HBase数据同步性
TODOList 多线程交互.RCP.事物控制.数据倾斜.HBase数据同步性 TODO List thread.join()如何互相之间通知? 线程池何时最后运行完成? MemCache性能要优于R ...
- ACM POJ 1146 ID Codes
题目大意:输入一个字符串.输出它的下一个字典序排列. 字典序算法思想: 1.从右向左寻找字符串找出第一个a[i]<a[i+1]的位置i; 2.从右向左找出第一个大于a[i]的元素a[j]; 3. ...
- JAVA:从public static void main(String args[])開始
我们都知道当你要执行一个JAVA文件的时候必需要有一个main函数. 这是为什么呢? 跟C语言的道理一样,当你执行一个文件的时候.你必需要有一个入口函数或者入口地址,在C里面是main函数.相同的在J ...
- 本地搭建MongoDB Server
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/ Overview Requirements Get Mongo ...
- 图解时间复杂度O(n)
画一个16个格子.大O表示计算的操作数. 算法1 需要16步. 算法2 算法1的时间复杂度为O(n) 算法2的时间复杂度为O(logn) n为元素个数16 O中的内容为操作的次数 5种常用的时间复杂度
- 可以通过shadowserver来查看开放的mdns(用以反射放大攻击)——中国的在 https://mdns.shadowserver.org/workstation/index.html
Open mDNS Scanning Project 来自:https://mdns.shadowserver.org/ If you are looking at this page, then m ...