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 ...
随机推荐
- android 开源 + 一些素材网站
ui 设计工具:http://www.sketchcn.com/ 分类汇总: https://github.com/Trinea/android-open-project 直接拿来用!最火的Andro ...
- 使用.NET中的Action及Func泛型委托
委托,在C#编程中占有极其重要的地位,委托可以将函数封装到委托对象中,并且多个委托可以合并为一个委托,委托对象则可以像普通对象一样被存储.传递,之后在任何时刻进行调用,因此,C#中函数回调 ...
- 【ToolGood.Words】之【StringSearch】字符串搜索——基于BFS算法
字符串搜索中,BFS算法很巧妙,个人认为BFS算法效率是最高的. [StringSearch]就是根据BFS算法并优化. 使用方法: string s = "中国|国人|zg人|fuck|a ...
- jquery获取当前元素的坐标
jquery获取当前元素的坐标 1,获取对象 var obj = $("#id号"); 或 var obj = $(this); 实例中我获取的对象是弹出窗口按钮,这样创建的新窗 ...
- arm_cm4.c关于kinetis的修改
/***********************************************************************/ /* * Initialize the NVIC t ...
- TAxThread - Inter thread message based communication - Delphi
http://www.cybletter.com/index.php?id=3 http://www.cybletter.com/index.php?id=30 Source Code http:// ...
- ARM体系架构下的同步操作
http://blog.hamobai.com/2012/06/28/synchronization-on-ARM-one/ 处理器在访问共享资源时,必须对临界区进行同步,即保证同一时间内,只有一个对 ...
- Apache、Tomcat、JBoss、Weblogic四个常用的JavaEE服务器
Apache全球应用最广泛的http服务器,免费,出自apache基金组织 Tomcat应用也算非常广泛的web 服务器,支持部分j2ee,免费,出自 apache基金组织 JBoss开源的应用服务器 ...
- Android编程之仿微信显示更多文字的View
微信朋友圈中,如果好友发表的文字过长,会自动收缩起来,底下有提示,当点击“显示更多”时才会展开. 首先定义布局文件(很简单,不解释): <?xml version="1.0" ...
- windows下安装,配置gcc编译器
在Windows下使用gcc编译器: 1.首先介绍下MinGW MinGW是指仅仅用自由软件来生成纯粹的Win32可运行文件的编译环境,它是Minimalist GNU on Windows的略称. ...