【比赛】NOIP2017 时间复杂度

 

恶心的模拟题,考场上犯了一堆错误,多组数据清空没清完、数组开小。。。民间都是50分,结果CCF90。。

考完后随便改改就过了,还好只少了10分,如果真的是50,我估计会疯掉。

因为考场的时候没写好,所以最终的代码也很难看。

 

  1 #include<bits/stdc++.h>
  2 using namespace std;
  3 int T,n,stk[100],p[100],fnum,stack_num,sck[110],sck_num;
  4 char s[20],ch[2],res[100];
  5 inline void init()
  6 {
  7     memset(p,0,sizeof(p));
  8     memset(res,0,sizeof(res));
  9     memset(sck,0,sizeof(sck));
 10     memset(stk,0,sizeof(stk));
 11     sck_num=0;
 12     stack_num=0;
 13     fnum=0;
 14 }
 15 inline void Dealwith()
 16 {
 17     init();
 18     int ans=0,mark=0,nxt=1,nnum=0,las=0,done=0;
 19     for(register int i=1;i<=n;++i)
 20     {
 21         scanf("%s",ch);
 22         if(ch[0]=='F')
 23         {
 24             if(done)
 25             {
 26                 scanf("%s",ch);
 27                 scanf("%s",ch);
 28                 scanf("%s",ch);
 29                 continue;
 30             }
 31             fnum++;
 32             scanf("%s",ch);
 33             if(p[ch[0]-'a'])
 34             {
 35                 printf("ERR\n");
 36                 done=1;
 37             }
 38             p[ch[0]-'a']=1;
 39             stk[++stack_num]=ch[0]-'a';
 40             int fl1,num1=0,fl2,num2=0;
 41 
 42             scanf("%s",ch);
 43             if(ch[0]>='0'&&ch[0]<='9')
 44             {
 45                 fl1=0;
 46                 for(register int j=0;j<strlen(ch);++j)num1=(num1<<3)+(num1<<1)+(ch[j]^'0');
 47             }
 48             else fl1=1;
 49 
 50             scanf("%s",ch);    
 51             if(ch[0]>='0'&&ch[0]<='9')
 52             {
 53                 fl2=0;
 54                 for(register int j=0;j<strlen(ch);++j)num2=(num2<<3)+(num2<<1)+(ch[j]^'0');
 55             }
 56             else fl2=1;
 57 
 58             if(fnum!=nxt)continue;
 59 
 60             if(fl1==1&&fl2==0)nxt=fnum;
 61             else if(fl1==0&&fl2==0)
 62             {
 63                 if(num1>num2)nxt=fnum;
 64                 else nxt=fnum+1,sck[++sck_num]=1;
 65             }
 66             else if(fl1==0&&fl2==1)
 67             {
 68                 mark=1;
 69                 nnum++;
 70                 if(ans<nnum)ans++;
 71                 nxt=fnum+1;
 72                 sck[++sck_num]=2;
 73             }
 74             else sck[++sck_num]=1,nxt=fnum+1;
 75         }
 76         else
 77         {
 78             if(done)continue;
 79             if(!fnum)
 80             {
 81                 printf("ERR\n");
 82                 done=1;
 83             }
 84             if(done)continue;
 85             if(nxt==fnum+1)
 86             {
 87                 fnum--,nxt--;
 88                 if(sck[sck_num--]==2)nnum--;
 89             }
 90             else fnum--;
 91             p[stk[stack_num--]]=0;
 92         }
 93     }
 94     if(done)return ;
 95     if(fnum)
 96     {
 97         printf("ERR\n");
 98         return ;
 99     }
100     if(mark)
101     {
102         res[0]='O',res[1]='(',res[2]='n',res[3]='^';
103         int respos=3,tmppos=0;
104         char tmp[10];
105         while(ans)tmp[++tmppos]=ans%10+'0',ans/=10;
106         while(tmppos)res[++respos]=tmp[tmppos--];
107         res[++respos]=')';res[++respos]='\0';
108     }
109     else res[0]='O',res[1]='(',res[2]='1',res[3]=')',res[4]='\0';
110 
111     if(!strcmp(s,res))printf("Yes\n");
112     else printf("No\n");
113 }
114 int main()
115 {
116     freopen("complexity.in","r",stdin);
117     freopen("complexity.out","w",stdout);
118     scanf("%d",&T);
119     while(T--)
120     {
121         scanf("%d",&n);scanf("%s",s);
122         Dealwith();
123     }
124     return 0;
125 }
NOIP2017 时间复杂度

 

posted @ 2017-12-07 20:13  HYJ_cnyali  阅读(518)  评论(0编辑  收藏  举报