• [NOIP2017 TG D1T2]时间复杂度


    题目大意:

    题解:模拟

    卡点:1.数组忘清空

    (考场代码风格独特。。。)

    C++ Code:

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    using namespace std;
    const int inf=2000;
    int T,n,F,E,top,ls,ans,temp,can,w;
    char ch,s[10000];
    string p;
    bool pd,halt,llw[10000];
    bool read(int &x){
        char t=getchar();bool pd=0;
        while(t<'0'||t>'9'){
            if (t=='^')pd=1;
            t=getchar();
        }
        for (x=t^48,t=getchar();t>='0'&&t<='9';t=getchar())x=x*10+(t^48);
        return pd;
    }
    int main(){
    //	freopen("complexity.in","r",stdin);
    //	freopen("complexity.out","w",stdout);
        scanf("%d",&T);
        while (T--){
            scanf("%d",&n);
    //		printf("Debug:%d
    ",n);
            pd=read(w);
    //		printf("D:%d
    ",w);
            getline(cin,p);
            top=0;can=inf;
            halt=false;
            ans=temp=0;
            for (int i=0;i<n;i++){
                int x,y;
                char cha; 
                getline(cin,p);
                ls=p.length();
    //			cout << "lalal" << p << endl;
                if (halt)continue;
                if (p[0]=='F'){
                    int now;
                    for (now=1;now<ls;now++)if (p[now]!=' ')break;
                    ch=p[now];
                    for (int j=0;j<top;j++)if (ch==s[j]){
                        puts("ERR");
                        halt=1;
                        continue;
                    }
                    if (halt)continue;
                    s[top++]=ch;
                    llw[top-1]=0;
                    if (can<top)continue;
                    for (now++;now<ls;now++)if (p[now]!=' ')break;
                    if (p[now]=='n')x=inf;
                        else {
                            for (x=p[now]^48,now++;p[now]>='0'&&p[now]<='9';now++)x=x*10+(p[now]^48);
                        }
                    for (now++;now<ls;now++)if (p[now]!=' ')break;
                    if (p[now]=='n')y=inf;
                        else {
                            for (y=p[now]^48,now++;p[now]>='0'&&p[now]<='9';now++)y=y*10+(p[now]^48);
                        }
    //				printf("DEBUG:%d %d
    ",x,y);
                    if (x<y&&y==inf)temp++,llw[top-1]=1;
                    if (temp>ans)ans=temp;
    //                printf("%d
    ", temp);
                    if (x==y)llw[top-1]=0;
                    if (x<y&&y!=inf)llw[top-1]=0;
                    if (x>y)can=top,llw[top-1]=0;
                }else{
                    if (p[0]=='E'){
                        top--;
                        if (top<0){
                            puts("ERR");
                            halt=1;
                            continue;
                        }
                        if (llw[top])temp--;
                        if(can>=top)can=inf;
                    }
                }
            }
            if (top&&!halt){
                puts("ERR");
                halt=1;
            }
            if (!halt){
                if (pd){
                    if (ans==w)puts("Yes");
                        else puts("No");
                }else if (ans==0)puts("Yes");
                    else puts("No");
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    tomcat启动超时
    sqlserver存储过程及mybatis调用——待续
    linux各种顔色代表
    linux ngix安装
    vue 报错解决:TypeError: Cannot read property '_t' of undefined"
    给iview项目加一个i18n国际化翻译
    初探iview
    vue-eslint配置文件
    js中通过Object.prototype.toString方法----精确判断对象的类型
    判断是对象还是数组的方法
  • 原文地址:https://www.cnblogs.com/Memory-of-winter/p/9504307.html
Copyright © 2020-2023  润新知