hdu 4699 Editor 多校第十场 (模拟)
2013-08-24 20:09
375 查看
栈 L,R 维护光标之前(之后)的序列
那么 I x L.push(x);
D L.pop();
L R.push(L.pop());
R L.push(R.pop());
然后用 s[]数组维护前缀和,ans[] 数组维护前缀和的最大值
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 1000010;
vector<int>L,R;
int s[maxn];
int ans[maxn];
int main()
{
int T;
while(~scanf("%d",&T))
{
L.clear();
R.clear();
char op[2];
int tot=0;
s[0]=0;
while(T--)
{
scanf("%s",op);
if(*op=='I')
{
int x;
scanf("%d",&x);
L.push_back(x);
s[tot+1]=s[tot]+x;
tot++;
if(tot==1) ans[tot]=s[tot];
else ans[tot]=max(s[tot],ans[tot-1]);
}
else if(*op=='D')
{
if(L.size()==0) continue;
L.pop_back();
tot--;
}
else if(*op=='L')
{
if(L.empty()) continue;
R.push_back(L.back());
L.pop_back();
tot--;
}
else if(*op=='R')
{
if(R.empty()) continue;
L.push_back(R.back());
s[tot+1]=s[tot]+R.back();
R.pop_back();
tot++;
ans[tot]=max(s[tot],ans[tot-1]);
}
else if(*op=='Q')
{
int k;
scanf("%d",&k);
printf("%d\n",ans[k]);
}
}
}
}
那么 I x L.push(x);
D L.pop();
L R.push(L.pop());
R L.push(R.pop());
然后用 s[]数组维护前缀和,ans[] 数组维护前缀和的最大值
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 1000010;
vector<int>L,R;
int s[maxn];
int ans[maxn];
int main()
{
int T;
while(~scanf("%d",&T))
{
L.clear();
R.clear();
char op[2];
int tot=0;
s[0]=0;
while(T--)
{
scanf("%s",op);
if(*op=='I')
{
int x;
scanf("%d",&x);
L.push_back(x);
s[tot+1]=s[tot]+x;
tot++;
if(tot==1) ans[tot]=s[tot];
else ans[tot]=max(s[tot],ans[tot-1]);
}
else if(*op=='D')
{
if(L.size()==0) continue;
L.pop_back();
tot--;
}
else if(*op=='L')
{
if(L.empty()) continue;
R.push_back(L.back());
L.pop_back();
tot--;
}
else if(*op=='R')
{
if(R.empty()) continue;
L.push_back(R.back());
s[tot+1]=s[tot]+R.back();
R.pop_back();
tot++;
ans[tot]=max(s[tot],ans[tot-1]);
}
else if(*op=='Q')
{
int k;
scanf("%d",&k);
printf("%d\n",ans[k]);
}
}
}
}
相关文章推荐
- hdu 4699 Editor 模拟
- 2013 多校第九场 hdu 4699 Editor(vector OR splay tree)
- HDU 4699 Editor (栈的使用,模拟)
- 2017 多校训练第十场 HDU 6178 Monkeys 最小点覆盖+树形DP
- HDU 5387(2015多校8)-Clock(模拟)
- hdu 4705 Y 多校第十场
- hdu 5327 Olympiad (多校联赛) ——模拟
- HDU6168 Numbers(模拟,2017 HDU多校联赛 第9场)
- hdu 5289 Assignment(2015多校第一场第2题)RMQ+二分(或者multiset模拟过程)
- HDU 5402 Travelling Salesman Problem(多校9 模拟)
- HDU 5867 Water problem(模拟题目)【HDU多校联合8.18】
- hdu 5319 Painter (2015多校第三场第4题)暴力模拟(瞎搞)
- 多校7 HDU-6130 Kolakoski 构造数列 & 模拟
- hdu 4950 Monster 多校八 模拟
- HDU 2017 多校联合训练赛3 3003 6058 Kanade's sum 枚举 模拟链表
- hdu 5289 Assignment(2015多校第一场第2题)RMQ+二分(或者multiset模拟过程)
- HUD4699-Editor 模拟+数组处理
- hdu 4699 Editor(单调栈)
- 多校4 HDU-6077 Time To Get Up 模拟水题
- HDU-5821 多校训练第8场-1001(巧妙模拟)