hdu 4669 模拟
思路:
主要就是模拟这些操作,用链表果断超时。改用堆栈模拟就过了
#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 模拟的更多相关文章
- hdu 4891 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...
- HDU 4669 Mutiples on a circle 数位DP
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4669 考察对取模的的理解深不深刻啊,当然还有状态的设计····设d[i][j]表示以第i个数结尾,余 ...
- hdu 5012 模拟+bfs
http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...
- 2013杭州网络赛C题HDU 4640(模拟)
The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU/5499/模拟
题目链接 模拟题,直接看代码. £:分数的计算方法,要用double; #include <set> #include <map> #include <cmath> ...
- hdu 5003 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=5003 记得排序后输出 #include <cstdio> #include <cstring& ...
- hdu 5033 模拟+单调优化
http://acm.hdu.edu.cn/showproblem.php?pid=5033 平面上有n个建筑,每个建筑由(xi,hi)表示,m组询问在某一个点能看到天空的视角范围大小. 维护一个凸包 ...
- HDU 2860 (模拟+并查集)
Regroup Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu 5083(模拟)
Instruction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- 访问ControlTemplate内部的元素
需要用到code behind 注意要给需要访问的元素命名x:Name="PART_TextBlock" <ResourceDictionary xmlns="ht ...
- 配置IIS服务器,.apk文件下载
iis中支持下载apk文件, 发布的网站上右键->属性->HTTP头->下方有个按钮叫[MIME类型]->添加:两个栏, 扩展名填写: .apk MIME类型填写: 扩展名为 ...
- 《Spring3.0就这么简单》第1章快速入门
问题 [如何将jsp中传递到HttpServletRequest的参数,自动装配到Java对象中] [成功] public void setUsernAme(String username) < ...
- vc6.0 通过ADO(udl)连接sql 2008
转载声明:本文转自http://blog.sina.com.cn/s/blog_7328b9dd0100pkbw.html茗之的博客 首先声明:本文是针对vc与sql菜鸟的,高人请让路. 本文讲解 ...
- openflashchart + flex
Hello openflashchart+flex的demo: http://blog.webasp.com.au/2009/06/open-flash-chart-as-a-swc/ http:// ...
- linux 下使rdate命令支持ipv6 ntp server 同步时间
如果使用linux 下,busybox自带的rdate命令 去ipv6 的ntp server 同步时间的话,会提示invalid argument :无效参数. 那么现在下载rdate的源码并对其进 ...
- sql注入在线检測(sqlmapapi)
之前一搞渗透的同事问我.sqlmapapi.py是干啥的,我猜非常多人都玩过sqlmap,但玩过sqlmapapi的应该比較少,今天就和大家一起看看怎样使用以及一些美的地方. 说白了.sqlmapap ...
- Codeforces Round #311 (Div. 2) D. Vitaly and Cycle 图论
D. Vitaly and Cycle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/p ...
- linux下的文件操作——批量重命名
概述:在日常工作中,我们经常需要对一批文件进行重命名操作,例如将所有的jpg文件改成bnp,将名字中的1改成one,等等.文本主要为你讲解如何实现这些操作 1.删除所有的 .bak 后缀: renam ...
- ecmall widgets 挂件开发详解
Ecmall挂件开发 实质上是后台开发很多页面,分别去调用程序展示这些页面,达到首页内容更换很快的目的,这样做减少后续开发,开发人员只需开发挂件就可以了,至于位置可随意定.(还需调整html,但是起码 ...