• P3952 时间复杂度


    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    string tmp,b,a;
    int xu,e,circle,flag,stop,l[27],g[100002],h,t,n,maxn,val[109];
    int aa,bb;
    char aaa;
    
    void change(){
        xu=0,e=0,circle=0,flag=0,stop=0,h=0,n=0,maxn=0;
        memset(l,0,sizeof(l));
        memset(g,0,sizeof(g));
        memset(val,0,sizeof(val));
    }
    void get_time(){
        if(tmp[2]>'0'&&tmp[2]<='9')
            xu=0;
        if(tmp[2]=='n'){
            xu=tmp[4]-'0';
            if(tmp[5]>='0'&&tmp[5]<='9')
                xu=xu*10+(tmp[5]-'0');//5写成4了 
        }
    }
    void get_F(){
        cin>>aaa;
        e++;
        circle++;
        if(l[aaa-'a'+1]==1)    flag=-1;
        g[e]=aaa-'a'+1;
        l[aaa-'a'+1]=1;
        cin>>a>>b;//没有处理好字母-‘a’,数字-‘0’的关系 
        if(a[0]=='n'&&b[0]=='n')    return;//没有想到当n=n时也可以继续进行 
        if(a[0]=='n'){    if(stop==0)    stop=e;} 
        else{
            if(b[0]=='n'&&stop==0)    h++,val[circle]=1;
            else{
                aa=0,bb=0;
                int num_a=a.size();
                int num_b=b.size();
                for(int i=0;i<num_a;i++)
                    aa=aa*10+(a[i]-'0');
                for(int i=0;i<num_b;i++)
                    bb=bb*10+(b[i]-'0');
                if(aa>bb){    if(stop==0)    stop=e;}
            }//逻辑非常混乱,一开始也没想到用string型的,老是把后面的E读进来 
        }
    }
    void get_E(){
        l[g[circle]]=0;
        maxn=max(maxn,h);
        if(val[circle]==1)    h--;//没有考虑让h--,使复杂度一直累加(在存在循环{ 循环(结束) 循环}时结果错误 
        circle--;
    }
    int main(){
        scanf("%d",&t);
        while(t--){
            change();//清零
            scanf("%d",&n);
            cin>>tmp;
            get_time(); 
            for(int i=1;i<=n;i++){
                cin>>aaa;
                if(aaa=='F')    get_F();
                if(aaa=='E')    get_E();
                if(circle==0){
                    maxn=max(maxn,h),h=0,e=0,stop=0;
                    memset(val,0,sizeof(val));
                }    
                if(i==n&&circle!=0)    flag=-1;
            }
            if(flag==-1)    printf("ERR
    ");
            else if(xu==maxn)    printf("Yes
    ");
            else printf("No
    ");
        }
        return 0;
    }
    View Code

    这个题我没有死抠题解因为我发现像这种题面很白痴,逻辑性要求非常之强的题,去理解别人的代码还不如自己去构造。

    心态有点崩,出现了很多低级错误,

    好处是锻炼了我的调试能力和耐心。

    做出来后感觉也不是很难。

  • 相关阅读:
    CodeForces
    4.15随笔
    oracle新建用户并赋予权限等
    catch时,获取异常信息
    ORACLE 判断是否为数字类型
    UNION ALL用法
    2019.11.7随笔
    oracle 查询锁表和解锁
    2019.11.1随笔
    oracle拼接子查询返回的多个结果
  • 原文地址:https://www.cnblogs.com/jindui/p/11214976.html
Copyright © 2020-2023  润新知