我已经发过一篇很拙劣的题解了,现在估计再审核中
by wh_ZH @ 2017-04-22 23:45:01
```cpp
#include<cstdio>
#include<queue>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<limits.h>
#include<utility>
#include<cmath>
#include<algorithm>
#include<stack>
#define R register
#define rint R int
#define ll long long
#define I inline
#define ill I ll
#define iint I int
#define ivoid I void
#define ibool I bool
#define ichar I char
#define ipair I pair
#define xx first
#define yy second
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define maxn 100500
using namespace std;
struct _in{
template<typename T>
const _in&operator,(T&a)const
{
rint f=1;char g=getchar();
while(g>'9'||g<'0'){if(g=='-')f=-1;g=getchar();}
while(g>='0'&&g<='9'){a=a*10+g-'0';g=getchar();}
a*=f;
return*this;
}
}in;
ll mi(ll a,ll b)
{
ll base=a,tot=1;
while(b!=0)
{
if(b%2==1)
{
tot*=base;
}
base*=base;
b/=2;
}
return tot;
}
char s[maxn];
int len;
int ans[maxn],st[maxn],tot=1;
int main()
{
scanf("%s",s+1);
len=strlen(s+1);
for(rint i=1;i<=len;i++){
if(s[i]=='a'){
st[tot]++;
continue;
}
else if(s[i]=='('){
tot++;
continue;
}
else if(s[i]=='|'){
ans[tot]=max(ans[tot],st[tot]);
st[tot]=0;
continue;
}
else if(s[i]==')'){
ans[tot]=max(ans[tot],st[tot]);
st[tot-1]+=ans[tot];
ans[tot]=0;
st[tot]=0;
tot--;
continue;
}
}
printf("%d\n",max(ans[1],st[1]));
return 0;
}
```
//我不想写题解了,太麻烦,尽管我的方法和题解不一样。
我的方法是直接循环,'|'的左边最大我存在ans数组中,当前计算的最大存在st数组中,tot表示栈的深度,具体操作见代码。
by Sasiyar @ 2018-12-31 16:46:09
@[你好啊,再见](/space/show?uid=22673)
by Sasiyar @ 2018-12-31 16:46:24