HDU 4699 题解
来源:互联网 发布:好看的电影知乎 编辑:程序博客网 时间:2024/05/22 18:21
题目大意
实现一个类似编辑器的东西,有五种操作
I x:在指针前插入一个数x
D:删除指针前的数
L:把指针往左移一个位置
R:把指针往右移一个位置
Q k:查询位置1~k的最大前缀和
我的做法
用两个栈维护指针左右两边的数
维护前缀和、最大前缀和
I操作等于在第一个栈插入一个元素
D操作等于弹出第一个栈顶的元素
L和R操作等于弹出一个栈顶的元素,再往另一个栈插入一个元素
Q操作直接输出答案
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int t1[2000010];int t2[2000010];int a[2000010];int s[2000010];int top1,top2;int main(){ int n; while(~scanf("%d",&n)) { a[0]=0x80000000; s[0]=0; top1=top2=0; int x; char c[100]; int i; for(i=1;i<=n;i++) { scanf("%s",c); if(c[0]=='I') { scanf("%d",&x); t1[++top1]=x; s[top1]=s[top1-1]+x; a[top1]=max(a[top1-1],s[top1]); } else if(c[0]=='D') { top1--; } else if(c[0]=='L') { if(top1) t2[++top2]=t1[top1--]; } else if(c[0]=='R') { if(top2) { t1[++top1]=t2[top2--]; s[top1]=s[top1-1]+t1[top1]; a[top1]=max(a[top1-1],s[top1]); } } else { scanf("%d",&x); printf("%d\n",a[x]); } } } return 0;}
0 0
- HDU 4699 题解
- hdu 4602题解
- hdu 1789题解
- HDU 4665 题解
- HDU 4710题解
- HDU 4715题解
- hdu 1087题解
- hdu 2844题解
- hdu 2845 题解
- hdu 4007题解
- hdu 4004题解
- hdu 1879题解报告
- HDU 2180 时钟 题解
- HDU 1425 sort 题解
- HDU 1015 Safecracker 题解
- HDU Computer Transformation1041 题解
- HDU 题解 1024
- hdu 4451Dressing题解
- AngularJs遇到的小坑与技巧
- Spring Boot学习总结(1)——Spring Boot入门
- ToLua学习笔记(一) 下载安装以及Example 01 HelloWorld
- ubuntu的一些设置_总结
- BZOJ2806 [Ctsc2012]Cheat
- HDU 4699 题解
- 页面对特殊字符的输入控制
- ubantu配置svn遇到的问题,怎么删除gvfs
- android.uid.system和sdcard
- 关于PHP中的定时任务crontab详解
- 加解密与编解码算法
- Photoshop初学者应了解的一些专业术语
- mybatis入门---helloworld程序开发步骤
- CentOS6.3 redhat下修复yum安装工具