Luogu

分析

竟然 1A 了

纯模拟,没什么好讲的,细节也很少。

代码

// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=100+10;
const int inf=200;

int n; char cpx[N],s[N]; int vis[256];
struct node { int a,b,c; } sta[N]; int top=0;

inline int get(char* s,int p) { int res=0;
    while (s[p]>='0'&&s[p]<='9') res=res*10+s[p]-'0',++p;
    return res;
}

int main() {
    int T; scanf("%d",&T);
    while (T--) { memset(vis,0,sizeof(vis)),top=0;
        scanf("%d %s\n",&n,cpx+1);
        int ERR=0,dep=0,flag=1,ans=0;
        for (re int i=1;i<=n;++i) {
            fgets(s+1,sizeof(s),stdin);
            if (ERR) continue;
            if (s[1]=='F') {
                char var=s[3];
                if (vis[var]) { ERR=1; continue; }
                vis[var]=1;
                int p=5,q=5;
                while (s[q]!=' ') ++q; ++q;
                int L=s[p]=='n'?inf:get(s,p);
                int R=s[q]=='n'?inf:get(s,q);
                if (L<=R) {
                    if (R==inf&&L!=inf) {
                        ++dep;
                        if (flag) ans=max(ans,dep);
                        sta[++top]=(node){var,flag,1};
                    }
                    else sta[++top]=(node){var,flag,0};
                } else {
                    flag=0,sta[++top]=(node){var,0,0};
                }
            } else {
                if (!top) { ERR=1; continue; }
                vis[sta[top].a]=0,flag=sta[top].b,dep-=sta[top].c,--top;
            }
        }
        if (top) ERR=1;
        if (ERR) puts("ERR");
        else {
            if (ans==0) puts(cpx[3]=='1'?"Yes":"No");
            else puts(get(cpx,5)==ans?"Yes":"No");
        }
    }
    return 0;
}
最后修改:2019 年 11 月 13 日 08 : 26 AM