[NOIP2017]时间复杂度(模拟)

sscanf读入数字,getline(cin,string)读一整行,其余暴力模拟即可。

 1 #include<cstdio>
 2 #include<string>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 #define rep(i,l,r) for (int i=(l); i<=(r); i++)
 7 typedef long long ll;
 8 using namespace std;
 9 
10 const int N=110;
11 int T,n,w[N];
12 char p[N],s[N];
13 string str;
14 
15 int main(){
16     freopen("comp.in","r",stdin);
17     freopen("comp.out","w",stdout);
18     for (scanf("%d",&T); T--; ){
19         scanf("%d%s",&n,p); int d,ans=0,top=0; bool flag=0;
20         if (p[2]=='1') d=0; else sscanf(p+4,"%d",&d);
21         rep(i,1,n){
22             if (flag) { getline(cin,str); continue; }
23             scanf("%s",p);
24             if (p[0]=='F'){
25                 scanf("%s",p); s[++top]=p[0]; int x=0,a,b;
26                 scanf("%s",p); if (p[0]=='n') a=101; else sscanf(p,"%d",&a);
27                 scanf("%s",p); if (p[0]=='n') b=101; else sscanf(p,"%d",&b);
28                 if (a>b) w[top]=0;
29                     else if (a<b && b==101) w[top]=2; else w[top]=1;
30                 rep(j,1,top-1) if (s[j]==s[top]) flag=1;
31                 rep(j,1,top){
32                     if (!w[j]) break;
33                     if (w[j]==2) x++;
34                 }
35                 ans=max(ans,x);
36             }else flag|=(--top<0);
37             scanf("\n");
38         }
39         flag|=top>0; puts(flag?"ERR":ans==d?"Yes":"No");
40     }
41     return 0;
42 }

猜你喜欢

转载自www.cnblogs.com/HocRiser/p/9840795.html
今日推荐