【洛谷P3952】[NOIP2017]时间复杂度

时间复杂度

题目链接

 

对于 100%的数据:L100 。

很明显的模拟题

然而考试时还是爆炸了。。

调了一下午。。

蒟蒻表示不会离线操作。。

 

直接贴代码:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 using namespace std;
 5 int t,m,ans,p,q,topc,topt,stack[110];
 6 string a,s1,s2,s3,s4,stackc[110];
 7 bool dayu(string x,string y)
 8 {
 9     if(x.length()<y.length()) return 0;
10     if(x.length()>y.length()) return 1;
11     else return x>y;
12 }
13 int main()
14 {
15     scanf("%d",&t);
16     while(t--)
17     {
18         topc=0;topt=0;
19         bool f=1;
20         ans=0;p=0;q=0;
21         scanf("%d",&m);
22         cin>>s1;
23         int lens1=s1.length();    
24         int i=4;
25         if(lens1==4) q=0;
26         else while(s1[i]!=')')
27         {
28             q=q*10+s1[i]-'0';
29             i++;
30         }
31         while(m--)
32         {
33             cin>>a;
34             if(a=="E")
35             {
36                 if(stack[topc]) p--;
37                 topc--;
38             }
39             if(topc<0)
40                 f=0;
41             if(a=="F")
42             {
43                 cin>>s2>>s3>>s4;
44                 if((s3=="n"&&s4!="n")||(s3!="n"&&s4!="n"&&dayu(s3,s4)))
45                 {
46                     topt=1;
47                     while(m&&topt&&f)
48                     {
49                         cin>>a;
50                         if(a=="F"){
51                             topt++;
52                             cin>>s2>>s3>>s4;
53                             for(int j=1;j<=topc;j++)
54                             if(stackc[j]==s2&&f) f=0;
55                         }
56                         else topt--;
57                         m--;
58                     }
59                     if(topt) f=0;
60                 }
61                 else
62                 {
63                     for(int j=1;j<=topc;j++)
64                     if(stackc[j]==s2&&f) f=0;
65                     if(f)
66                     {
67                         stackc[++topc]=s2;
68                         if(s3!="n"&&s4=="n")
69                         {
70                             stack[topc]=1;
71                             p++;
72                             ans=max(ans,p);
73                         }
74                         else stack[topc]=0;
75                     }
76                 }
77             }
78         }
79         if(topc!=0||!f)
80         {
81             f=0;
82             puts("ERR");
83         }
84         if(f&&ans==q)
85          puts("Yes");
86         else if(f)
87          puts("No");
88     }
89     return 0;
90 }

 

转载于:https://www.cnblogs.com/yjkhhh/p/8494936.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值