标签:lse tin 循环 pac empty oid class algorithm other
#include<map>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<deque>
using namespace std;
int t;
int l;
char fzd[10];
int num;
bool flag;
char b[210];
map<char,bool> mp;
deque<int> q;
int tot,pre[210],last[210],other[210],w[210];
void add(int x,int y)
{
tot++;
pre[tot]=last[x];
last[x]=tot;
other[tot]=y;
}
int dfs(int x)
{
int tmp=w[x],sum=0;
for(int p=last[x];p;p=pre[p])
{
int v=other[p];
if(w[v]==-1) continue;
sum=max(sum,dfs(v));
}
return tmp+sum;
}
int main()
{
scanf("%d",&t);
while(t--)
{
tot=0;
q.clear();
memset(last,0,sizeof(last));
memset(w,0,sizeof(w));
flag=0;
num=0;
mp.clear();
scanf("%d",&l);
scanf(" O(%s)",fzd+1);
int len=strlen(fzd+1);
if(len==1) num=0;
else
{
for(int i=3;i<=len-1;i++)
num*=10,num+=fzd[i]-'0';
}
for(int i=1;i<=l;i++)
{
char s;
cin>>s;
if(s=='F')
{
cin>>b[i];
if(mp[b[i]])
flag=1;
mp[b[i]]=1;
char kai[5],ed[5];
scanf("%s",kai+1);
scanf("%s",ed+1);
int l1=strlen(kai+1);
int l2=strlen(ed+1);
int num1=0,num2=0;
for(int j=1;j<=l1;j++)
{
if(kai[j]=='n')
{
w[i]=-1;
continue;
}
num1*=10;
num1+=kai[j]-'0';
}
for(int j=1;j<=l2;j++)
{
if(ed[j]=='n')
{
if(kai[1]!='n')
w[i]=1;
}
num2*=10;
num2+=ed[j]-'0';
}
if(w[i]==0)
{
if(num1<=num2)
w[i]=0;
else w[i]=-1;
}
if(kai[1]=='n'&&ed[1]=='n')
w[i]=0;
if(q.size()) add(q.back(),i);
if(q.empty()) add(0,i);
q.push_back(i);
}
else
{
if(q.empty())
{
flag=1;
continue;
}
mp[b[q.back()]]=0;
q.pop_back();
}
}
if(flag||q.size())
{
printf("ERR\n");
continue;
}
int ans=dfs(0);
if(ans==num)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
标签:lse tin 循环 pac empty oid class algorithm other
原文地址:https://www.cnblogs.com/lihan123/p/11808165.html