CSA Round #53 (Div. 2 only) Histogram Partition(模拟)
传送门
题意
给出一个数组A,你有一个数组B(一开始全为0),询问多少次操作后B转化为A
一次操作:选择一段区间,加上某个正整数
分析
构建一个栈,
输入一个数,若当前栈空或栈顶元素比输入小,则加入栈中,否则若大于栈顶元素,则删去栈顶元素,放入输入元素,复杂度O(n)
trick
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
int n;
stack<int>s;
int ans;
int main()
{
cin >> n;
F(i, 0, n)
{
int val = 0;
if (i < n) cin >> val;
if (!s.empty() && s.top() > val) {s.pop(); s.push(val); ans++;}
if (s.empty() || s.top() < val) s.push(val);
}
cout << ans << endl;
return 0;
}
CSA Round #53 (Div. 2 only) Histogram Partition(模拟)的更多相关文章
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- BestCoder Round #53 (div.1)
Problem A: 题目大意: 给出以节点1为根的一棵树A,判断它是否是特殊的.一棵树是特殊的当且仅当不存在和它不完全相同的一棵树B,使得A中点i到点1的距离和B中相等. 题解: 假设一个点x的深度 ...
- hdu 5424 Rikka with Graph II (BestCoder Round #53 (div.2))(哈密顿通路判断)
http://acm.hdu.edu.cn/showproblem.php?pid=5424 哈密顿通路:联通的图,访问每个顶点的路径且只访问一次 n个点n条边 n个顶点有n - 1条边,最后一条边的 ...
- HDU 5432 Rikka with Tree (BestCoder Round #53 (div.2))
http://acm.hdu.edu.cn/showproblem.php?pid=5423 题目大意:给你一个树 判断这棵树是否是独特的 一颗树是独特的条件:不存在一颗和它本身不同但相似的树 两颗树 ...
- CodeForce edu round 53 Div 2. D:Berland Fair
D. Berland Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Educational Codeforces Round 53 Div. 2翻车记
A:差点开场懵逼.只要有相邻两位不同就可以作为答案. #include<iostream> #include<cstdio> #include<cmath> #in ...
- csa Round #73 (Div. 2 only)
Three Equal Time limit: 1000 msMemory limit: 256 MB You are given an array AA of NN integers betwe ...
- csa Round #66 (Div. 2 only)
csa66 Risk Rolls Time limit: 1000 msMemory limit: 256 MB Alena and Boris are playing Risk today. W ...
- CSA Round #50 (Div. 2 only) Min Swaps(模拟)
传送门 题意 给出一个排列,定义\(value为\sum_{i=1}^{n-1}abs(f[i+1]-f[i])\) \(swap(a[i],a[j])(i≠j)为一次交换\),询问最少的交换次数使得 ...
随机推荐
- mongodb查看连接数、同步时间、oplog及修改表名的操作
1) mongodb查看连接数: db.serverStatus().connections; 2) mongodb查看同步时间: db.printSlaveReplicationInfo(); % ...
- PowerDesigner逆向工程,从SQL Server数据库生成Physical Model -----数据源方式
1.File-Reverse Engineer-Database 2.DBMS选择SQL Server 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 一路Next..... ...
- 多用GCD,少用performSelect系列方法
例如,要延后执行某项任务,可以有下面两种实现方式,而我们应该优先考虑第二种: // Using performSelect: withObject: afterDelay: [self perform ...
- 安卓Android手机直播推送同步录像功能设计与实现源码
本文转自:http://blog.csdn.net/jyt0551/article/details/58714595 EasyPusher是一款非常棒的推送客户端.稳定.高效.低延迟,音视频同步等都特 ...
- EasyDarwin做转发延时太大?
很多人反映,在用EasyDarwin做流媒体转发服务时,延时太大,实际Darwin在转发模块中,有一个控制转发Buffer时间的配置reflector_buffer_size_sec,我们将这个配置改 ...
- LogStash 日志搜集
安装 下载:https://download.elastic.co/logstash/logstash/logstash-2.4.0.tar.gz 解压到指定目录即可 配置 bin目录添加logsta ...
- Java开发面试题
- 远程访问Linux的常见方式
访问方式 不加密文字界面:telnet.rsh 加密文字界面:SSH 图形界面:Xdmcp.RDP.VNC SSH SSH用来取代finger.R shell(rlogin.rcp.rsh).teln ...
- Ubuntu搜狗输入法候选词乱码
打开Fcitx Configuration,进入Addon标签 选中Simplified Chinese To Traditional Chinese Convert Simplified ...
- ABAP 通过字段找表程序
2.获取数据保存在哪个数据表的方法: 1.前台对指定栏位 使用F1帮助找表,2.st05 跟踪业务操作过程,检索需要的数据表,(此方法找表很高效)3.对于文本字段找表,可以找到前台维护处,->维 ...