思路:

主要就是模拟这些操作,用链表果断超时。改用堆栈模拟就过了

#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Maxn 1000010
#define Maxm 300010
#define LL __int64
#define Abs(x) ((x)>0?(x):(-x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define inf 0x7fffffff
#define Mod 1000000007
int Max[Maxn],sum[Maxn];
using namespace std;
stack<int> br,af;
int main()
{
int i,j,u,v,n,x;
char str[];
int brz,afz;
while(scanf("%d",&n)!=EOF){
brz=afz=;
while(!br.empty())
br.pop();
while(!af.empty())
af.pop();
sum[]=;
Max[]=-;
for(i=;i<=n;i++){
scanf("%s",str);
if(str[]=='I'){
scanf("%d",&x);
br.push(x);
sum[++brz]=sum[brz-]+x;
Max[brz]=max(Max[brz-],sum[brz]);
}
if(str[]=='D'){
if(br.empty()) continue;
br.pop();
--brz;
}
if(str[]=='L'){
if(!br.empty()){
int temp=br.top();
br.pop();
--brz;
af.push(temp);
++afz;
}
}
if(str[]=='R'){
if(!af.empty()){
int temp=af.top();
af.pop();
br.push(temp);
--afz;
sum[++brz]=sum[brz-]+temp;
Max[brz]=max(Max[brz-],sum[brz]);
}
}
if(str[]=='Q'){
scanf("%d",&x);
if(x>=brz)
printf("%d\n",Max[brz]);
else
printf("%d\n",Max[x]);
}
}
}
return ;
}

hdu 4669 模拟的更多相关文章

  1. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

  2. HDU 4669 Mutiples on a circle 数位DP

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4669 考察对取模的的理解深不深刻啊,当然还有状态的设计····设d[i][j]表示以第i个数结尾,余 ...

  3. hdu 5012 模拟+bfs

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...

  4. 2013杭州网络赛C题HDU 4640(模拟)

    The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  5. HDU/5499/模拟

    题目链接 模拟题,直接看代码. £:分数的计算方法,要用double; #include <set> #include <map> #include <cmath> ...

  6. hdu 5003 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5003 记得排序后输出 #include <cstdio> #include <cstring& ...

  7. hdu 5033 模拟+单调优化

    http://acm.hdu.edu.cn/showproblem.php?pid=5033 平面上有n个建筑,每个建筑由(xi,hi)表示,m组询问在某一个点能看到天空的视角范围大小. 维护一个凸包 ...

  8. HDU 2860 (模拟+并查集)

    Regroup Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  9. hdu 5083(模拟)

    Instruction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. Oracle中wm_concat()函数的使用

    Oracle中wm_concat()函数的使用 wm_concat()函数是oracle行列转换函数,该函数可以把列值以‘,’分割开来,并显示成一行. 1.原数据: 2.把结果分组以‘|’分隔,以一行 ...

  2. ANSI_NULLS 和 QUOTED_IDENTIFIER

    1  ANSI_NULLS 当 SET ANSI_NULLS 为 ON 时,对空值进行等于 (=) 或不等于 (<>) 比较时取值为 FALSE    例如:SELECT * from t ...

  3. Flex XML

    一.创建XML类 1.把字符串对象转换为XML: var xmlStr:String="<students><student><name>吕布</n ...

  4. 学习tolua#·20多个例子

    初始项目搭建 clone官方库 新建unity工程 依次把官方库里的Assets和Unity5.x/Assets拷贝到项目Assets里 打开unity工程, 开始逐个学习例子,例子目录: 1. he ...

  5. html5 的缓存应用 manifest="filename.appcache"

    启动html5的应用缓存 <!DOCTYPE HTML> <html manifest="filename.appcache"> </html> ...

  6. Flex圆角矩形

    <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="h ...

  7. hdu 4497 GCD and LCM 数学

    GCD and LCM Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4 ...

  8. Codeforces Round #225 (Div. 1) C. Propagating tree dfs序+树状数组

    C. Propagating tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/383/p ...

  9. scu 4436: Easy Math 水题

    4436: Easy Math Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.scu.edu.cn/soj/problem.actio ...

  10. C#生成软件注册码

    开发软件时,当用到商业用途时,注册码与激活码就显得很重要了.现在的软件破解技术实在在强了,各种国内外大型软件都有注册机制,但同时也不断地被破解.下面发的只是一个常用版本,发出源码被破就更容易了,但我们 ...