求助RE
查看原帖
求助RE
526518
respect_lowsmile楼主2022/11/6 19:52

72pts72ptsRE on #8 ,#10 , #11,思路是开一个栈维护循环的 FF ,用一个字符串维护用过的变量,原因是 find,erasefind,erase 等函数便于维护标记的查找和释放。

#include<iostream>
#include<stack>
#include<map>
using namespace std;
stack<int> st;
string vis="";
inline int read()
{
    int s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9')
    {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')
    {s=s*10+ch-'0';ch=getchar();}
    return s*w;
}
int main()
{
    int T=read();
    while(T--)
    {
        while(!st.empty())  st.pop();vis="";
        int L=read(),flagc=0,flagf=0,cif=0,flagx=0,flage=0,cnt=0,ans=0;//flagx表示这层循环不能进入,压栈的时候压3,对复杂度有贡献的压2,常数压1 
        string s;//flage维护ERR
        cin>>s;
        if(s[2]=='1')  flagc=1;
        else
        {
            flagf=1;
            int pos=4;
            while(s[pos]>='0'&&s[pos]<='9'&&pos<=s.length()-1)    cif=cif*10+s[pos]-'0',pos++;
        }
        while(L--)
        {
            char ch;  string bi,l,r;
            cin>>ch;
            if(ch=='F')
            {
                cin>>bi>>l>>r;
                if(vis.find(bi)!=string::npos&&vis.find(bi)!=-1)  flage=1;
                //cout<<vis.find(bi)<<endl;
                vis+=bi;
                int L=0,R=0,pos1=0,pos2=0;
                if(l[0]=='n')  L=101;
                else while(l[pos1]>='0'&&l[pos1]<='9'&&pos1<=l.length()-1)  L=L*10+l[pos1]-'0',pos1++;
                if(r[0]=='n')  R=101;
                else while(r[pos2]>='0'&&r[pos2]<='9'&&pos2<=r.length()-1)  R=R*10+r[pos2]-'0',pos2++;
                if(L>R)  st.push(3),flagx=1;
                else if(R==101&&!flagx&&L!=101)  cnt++,st.push(2);
                else st.push(1);
            }
            if(ch=='E')
            {
                int len=vis.length();
                ans=max(ans,cnt);
                if(!flage)  vis.erase(len-1,1);
                if(st.empty())  flage=1;
                else if(st.top()==3)  flagx=0,st.pop();
                else if(st.top()==2)  cnt--,st.pop();
                else if(st.top()==1)  st.pop();    
            }
        }
        if(flage)  printf("ERR \n");
        else if(st.size())  printf("ERR\n");
        else if(flagc&&ans==0)  printf("Yes\n");
        else if(flagf&&ans==cif)  printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}
2022/11/6 19:52
加载中...