思路:

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

#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. Innodb的事务与日志 & JTA事务

    InnoDB引擎的行锁是通过加在什么上完成(或称实现)的?为什么是这样子的 通过   行多版本控制 MyISAM                  Innodb 事物支持 :   不支持       ...

  2. application与cache

    每个项目都有一些全局,常用的信息,而这些信息如果在每次使用时都载入,那必将耗费很大的资源,特别是对访问压力大的系统.因此,这个情况中,把这些全局信息放到缓存中是很必要的,放在缓存中可以使得数据能够很快 ...

  3. UDP套接口编程

    常用的UDP实现的程序:DNS域名系统,NFS网络文件系统,SNMP简单网络管理协议 ssize_t recvfrom(int sockfd,void *buff,size_t nbytes,int ...

  4. jquery视频展示 图片轮播

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. cocos2dx 网络编程(CCHttpRequest和CURL两个方式)

    转自:http://blog.csdn.net/sg619262284/article/details/20144087 在使用之前需要设置一些参数:参考:http://blog.csdn.net/w ...

  6. Android ndk下用AssetManager读取assets的资源

    转自:http://www.cppblog.com/johndragon/archive/2012/12/28/196754.html 在使用 cocos2dx 在 Android 上进行游戏开发时, ...

  7. Ember学习(8):REOPENING CLASSES AND INSTANCES

    英文原址:http://emberjs.com/guides/object-model/reopening-classes-and-instances/ 你不须要一次就完毕类所有内容的定义,通过reo ...

  8. jquery动态创建form并提交到.ashx文件处理

        有时候在写web 应用的时候,需要临时动态构造一个form 并提交,form 里面的参数以及action,以及是post请求还是get请求,甚至form 的样式都是可以指定的,用原生的java ...

  9. Codeforces Round #340 (Div. 2) D. Polyline 水题

    D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...

  10. Android C2DM学习 - 云端推送

    一.基础知识 当我们开发需要和服务器交互的应用程序时,基本上都需要获取服务器端的数据,比如<地震及时通>就需要及时获取服务器上最新的地震信息.要获取服务器上不定时更新的信息一般来说有两种方 ...