HDOJ -- 4699
Editor
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1236 Accepted Submission(s): 391

I 2
I -1
I 1
Q 3
L
D
R
Q 2
3
The following diagram shows the status of sequence after each instruction:
#include<stack>
#include<cstdio>
#include<cstring>
#define MAX 1000005
using namespace std;
stack<int>l, r;
long long int dp[MAX], sum[MAX], n, temp;
char str[];
int main(){
freopen("in.c", "r", stdin);
while(~scanf("%lld", &n)){
while(!l.empty()) l.pop();
while(!r.empty()) r.pop();
memset(sum, , sizeof(sum));
memset(dp, , sizeof(dp));
dp[] = -;
for(int i = ;i < n;i ++){
scanf("%s", str);
if(str[] == 'I'){
scanf("%lld", &temp);
l.push(temp);
sum[l.size()] = sum[l.size()-] + temp;
dp[l.size()] = max(sum[l.size()], dp[l.size()-]);
}else if(str[] == 'L'){
if(!l.empty()){
int del = l.top();
l.pop();
r.push(del);
}
}else if(str[] == 'Q'){
scanf("%lld", &temp);
temp = min(temp, (long long int)l.size());
l.size() == ? printf("0\n") : printf("%lld\n", dp[temp]);
}else if(str[] == 'D') l.pop();
else{
if(!r.empty()){
int del = r.top();
r.pop();
l.push(del);
sum[l.size()] = sum[l.size()-] + del;
dp[l.size()] = max(sum[l.size()], dp[l.size()-]);
}
}
}
}
}
HDOJ -- 4699的更多相关文章
- HDU/HDOJ 4699 Editor
对顶栈算法. 此题充分说明了cin的不中以及scanf的优越性. 我TM用cin超时了!!!换成scanf就A了!!! #include <cstdio> #include <cst ...
- HDOJ 4699 Editor 栈 模拟
用两个栈模拟: Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDOJ 4699 Editor 对顶栈模拟
Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- hdoj 1385Minimum Transport Cost
卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...
- HDOJ(2056)&HDOJ(1086)
Rectangles HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...
随机推荐
- CF Round#240题解
第一次参加CF的比赛,MSK19.30,四个小时的时差真心累,第一次CODE到这么夜-- 一开始做了A,C两题,后来做B题的时候我体力和精神集中度就很低了,导致一直WA在4-- 今天起床后再刷B,终于 ...
- 九度OJ 1124 Digital Roots -- 数位拆解
题目地址:http://ac.jobdu.com/problem.php?pid=1124 题目描述: The digital root of a positive integer is found ...
- linux shell 逻辑运算符
一.逻辑卷标 逻辑卷标 表示意思 1. 关于档案与目录的侦测逻辑卷标! -f 常用!侦测『档案』是否存在 eg: if [ -f filename ] -d 常用!侦测『目录』是否存在 -b 侦测是否 ...
- jQuery DataTables 插件使用笔记
初始化 在页面中 <!DOCTYPE html> <html> <head> <link rel="stylesheet" type=&q ...
- wcf通道Channel
正文 客户端与服务进行交互的过程是通过通道进行交互的.客户端通过调用代理类执行相应的方法,通过通道编码,调用上下文,传输客户端的事务,管理可靠会话,对消息正文的加密,最后要执行的通道是传输通道就像我们 ...
- css动画怎么写:3个属性实现
3个属性:transition,animation,transform 实现步骤: 1.css定位 2.rgba设置颜色透明度 3.转换+动画 transform+animation 4.动画平滑过渡 ...
- (转载)delphi中获取汉字的拼音首字母
delphi中获取汉字的拼音首字母1.py: array[216..247] of string = ({216}'CJWGNSPGCGNESYPB' + 'TYYZDXYKYGTDJNMJ' + ' ...
- 快速生成json实体类
读取一个json文件,并与实体相对应: static void Main(string[] args) { string json = ""; FileStream fs = ne ...
- 本博客css style
#navList { min-height: 60px; } #navList li { height: 60px; } #navList a { margin: 0px 5px !important ...
- Servlet和Tomcat部署
今天有空写个Servlet来玩一下.用EditPlus写一个简单的Servlet,FirstServlet.java,如下: import java.io.IOException; import ja ...