思路:

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

#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. UI:target-action设计模式、手势识别器

    ⼀.target/action设计模式 ⼆.代理设计模式 三.UIImageView 四.⼿势识别器 target/action设计模式 耦合是衡量⼀个程序写的好坏的标准之⼀, 耦合是衡量模块与模块之 ...

  2. 表单input按钮在各浏览器之间的兼容性

    从网上看了这篇关于表单input按钮的浏览器兼容性问题,总结的还不错,所以copy下来学习下. input按钮在各个浏览器之间的兼容性问题,看下边这段代码: input.item { backgrou ...

  3. 全代码实现ios-3

    决定做ios开发的时候,看了很多本关于ios开发的书籍,其中有国内的人写的,也有根据外国的书翻译过来的. 很可惜,这些书里的例子没办法照搬过来,因为Xcode更新换代太快了,而这些书本的内容更新的速度 ...

  4. JSON的解析

    一:JSON字符串转换为JSON对象 JSON 最常见的用法之一,是从 web 服务器上读取 JSON 数据(作为文件或作为 HttpRequest),将 JSON 数据转换为 JavaScript ...

  5. Java常见排序算法之快速排序

    在学习算法的过程中,我们难免会接触很多和排序相关的算法.总而言之,对于任何编程人员来说,基本的排序算法是必须要掌握的. 从今天开始,我们将要进行基本的排序算法的讲解.Are you ready?Let ...

  6. PHP 获取js中变量的方法

    留作笔记 <php? $aaa="<script>document.write(1)</script>"; echo $aaa; ?> 其中数字 ...

  7. MySQL中MySQL X.X Command Line Client一闪而过的问题

    问题介绍:我安装完MySQL(我安装的是5.5)后,使用MySQL 5.5 Command Line Client,每次点击,总是一闪而过.解决方法如下:      首先进入cmd 切入MySQL的安 ...

  8. hdu 5277 YJC counts stars 暴力

    YJC counts stars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  9. C# udpclient 发送数据断网后自动连接的方法

    需求 有一个winform程序, 用来调试路由器和对路由器吞吐量进行测试 需要后台不断的接收来自udp服务器端的数据,同时要发送数据到服务器端(无线路由器) 设计时候,通过一个线程,for(;;)死循 ...

  10. iis7.5配置.net mvc注意事项

    iis7.5配置.net mvc注意事项   1. 应用程序池采用经典模式,framework4.0.可能存在权限问题,解决办法:在高级设置的标识设为LocalSystem.一般mvc都采用集成模式, ...