【HDU 4699】 Editor
【题目链接】
http://acm.hdu.edu.cn/showproblem.php?pid=4699
【算法】
维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数
在维护栈的同时求最大前缀和,即可
【代码】
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + ;
const int INF = 2e9; class mstack
{
private :
int tot;
int s[MAXN];
public :
inline void clear()
{
tot = ;
}
inline void push(long long x)
{
tot++;
s[tot] = x;
}
inline void pop()
{
tot--;
}
inline long long top()
{
return s[tot];
}
inline bool empty()
{
return tot == ;
}
} s1,s2; int q,pos;
long long x;
long long sum[MAXN],f[MAXN];
char opt[]; int main()
{ while (scanf("%d",&q) != EOF)
{
f[] = -INF;
s1.clear();
s2.clear();
pos = ;
while (q--)
{
scanf("%s",&opt);
if (opt[] == 'I')
{
scanf("%lld",&x);
s1.push(x);
pos++;
sum[pos] = sum[pos-] + x;
f[pos] = max(f[pos-],sum[pos]);
}
if (opt[] == 'D')
{
if (s1.empty()) continue;
s1.pop();
pos--;
}
if (opt[] == 'L')
{
if (s1.empty()) continue;
x = s1.top();
s1.pop();
s2.push(x);
pos--;
}
if (opt[] == 'R')
{
if (s2.empty()) continue;
x = s2.top();
s2.pop();
s1.push(x);
pos++;
sum[pos] = sum[pos-] + x;
f[pos] = max(f[pos-],sum[pos]);
}
if (opt[] == 'Q')
{
scanf("%lld",&x);
printf("%lld\n",f[x]);
}
}
} return ; }
【HDU 4699】 Editor的更多相关文章
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- 【hdu 1043】Eight
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...
- 【HDU 3068】 最长回文
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...
- 【HDU 4864】 Task
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4864 [算法] 贪心 不妨将两个数组分别按x从大到小排序 然后枚举每件物品,选择x值大于该物品的且 ...
随机推荐
- java_IO_2
1.字节流 InputStream(抽象类) package ioStudy; import java.io.File; import java.io.FileInputStream; import ...
- oracle查询没有主键的表
select table_name from user_tables a where not exists (select * from user_constraints b where b.cons ...
- Leetcode 498:对角线遍历Diagonal Traverse(python3、java)
对角线遍历 给定一个含有 M x N 个元素的矩阵(M 行,N 列),请以对角线遍历的顺序返回这个矩阵中的所有元素,对角线遍历如下图所示. Given a matrix of M x N elemen ...
- spring 中属性scope 的prototype(有状态)和singleton(无状态)
默认情况下,从bean工厂所取得的实例为Singleton(bean的singleton属性) Singleton: Spring容器只存在一个共享的bean实例, 默认的配置. Prototype: ...
- Window下的———TOMCAT环境的配置
1. 先去官方网站下载需要的猫(tomcat) http://tomcat.apache.org/ 2.下载好包,然后解压出来,放在你需要的位置上 3.去到配环境变量的地方,进行相应的环境配置 ...
- vue中axios设置
//设置默认全局baseURL axios.defaults.baseURL=process.env.BASE_API; //设置默认全局携带浏览器cookie axios.defaults.with ...
- Tree(树的还原以及树的dfs遍历)
紫书:P155 uva 548 You are to determine the value of the leaf node in a given binary tree that is th ...
- 3.2.1.1 POSIX方括号表达式
为配合非英语的环境,POSIX 标准强化其字符集范围的能力(例如,[a-z]),以匹配非英文字母字符. POSIX 也在一般术语上作了些变动,我们早先看到的范围表达式在 UNIX ...
- type="timestamp"与type="date"区别
type="timestamp"-----数据库中保存的时间为年月日时分秒 与type="date"---------数据库中保存的时间为年月日
- Codeforces Round #240 (Div. 2) D
, b2, ..., bl (1 ≤ b1 ≤ b2 ≤ ... ≤ bl ≤ n) is called good if each number divides (without a remainde ...