Editor

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

Problem Description
 
Sample Input
8
I 2
I -1
I 1
Q 3
L
D
R
Q 2
 
Sample Output
2
3

Hint

The following diagram shows the status of sequence after each instruction:

 
 
一直wa,谁能告诉我哪错了!
 
 #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的更多相关文章

  1. HDU/HDOJ 4699 Editor

    对顶栈算法. 此题充分说明了cin的不中以及scanf的优越性. 我TM用cin超时了!!!换成scanf就A了!!! #include <cstdio> #include <cst ...

  2. HDOJ 4699 Editor 栈 模拟

    用两个栈模拟: Editor Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  3. HDOJ 4699 Editor 对顶栈模拟

    Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...

  4. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  6. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  8. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  9. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

随机推荐

  1. ServiceStack.Redis 破解

    在github上下载了ServiceStack.Redis,做测试发现有限制,居然从v4开始就收费,无聊时,做了个源码分析 废话不多,上测试代码 try { ; i < ; i++) { red ...

  2. javascript 将多维数组转换为一维数组

    /** * 2013年9月去面试的时候,有面试过这样子一道题目: * 题目是这样子的:将一个多维数组转换成一维数组并返回该数组,类似 * [1,2,3,[4,5,6,[7,8]],9]转换后为:[1, ...

  3. HDU 3127 WHUgirls(DP 完全背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3127 题目大意:将一块长x宽y的矩形布料,剪成小的矩形(每个给定的小矩形都对应一个价值),使得所有小矩 ...

  4. ci 多个文件同时上传

    // 单个文件请手册,这里多个文件中,参数设置可参考手册 view 视图 <form...> <input type="file" name="user ...

  5. ubuntu 下安装 apache php mysql

    ubuntu 安装 apache+php+mysql1.打开终端,输入“sudo apt-get install apache2”,回车;(安装apache2.0或2.x新版本,系统会自动查找新的版本 ...

  6. 默认时,销毁会话,session_unset, session_destory

    <?php /** 一般我们登录时,开启了会话,就会自动生成 session 有关的文件, 保存有相关的用户登录信息,所以正常情况下得退出登录, 同时也要清空 session 有关的文件和相关的 ...

  7. SVG

    目前SVG在国内的使用并不常见,并且关于svg的相关js库也不多,这里指出两款svg的库Snap.svg和svg.js,Snap.svg张鑫旭的博客上有关于他的使用APi http://www.zha ...

  8. Js 中json简单处理

    Json2.js下载地址 json常用处理 Json字符串 var str = '{"code":10,"msg":"codemsg",&q ...

  9. IOS webview中cookie的读取与保存-b

    Cookie 的读取 将它放在 webViewDidFinishLoad 开始后执行 NSArray *nCookies = [[NSHTTPCookieStorage sharedHTTPCooki ...

  10. BZOJ 1754: [Usaco2005 qua]Bull Math

    Description Bulls are so much better at math than the cows. They can multiply huge integers together ...