zoukankan      html  css  js  c++  java
  • joj2035

    一开始超时,怎么改都超时,后来果断把stl换成纯数组,竟然AC了,莫非stl的操作很费时间吗,不解:

    之前的超时stl版:

    #include<iostream>
    #include<stack>
    #include<queue>
    using namespace std;
    int mark[10005];
    int main()
    {
        int n;
       
        while(scanf("%d",&n),n>0)
        {
          if(n==0)
            continue;
          memset(mark,0,sizeof(mark));
          vector<int> s1;
          queue<int> s2;
          int i,a;
          for(i=0;i<n;i++)
          {
             scanf("%d",&a);
             s1.push_back(a);
          }
          for(i=0;i<n;i++)
          {
             scanf("%d",&a);
             s2.push(a);
          }
          int t=s2.front();
          printf("%d\n",t);
          int count=0;
          while(s1[count]!=s2.front())
          {
               mark[s1[count]]=-1;
               count++;
          }
          s2.pop();
          while(s2.size()!=0)
          {  
              int m=s2.front();
              if(mark[m]==-1)
              {
                 s2.pop();
              }
              else
              {
                 int i;
                 printf("%d\n",m);
                 for(i=count-1;s1[i]!=m;i++)
                 {
                     mark[s1[i]]=-1;
                 }
                 s2.pop();
              }
          }
        }
    }

    改良版:

    #include<iostream>
    #include<stack>
    #include<queue>
    using namespace std;
    int mark[10005];
    int s1[10005];
    int s2[10005];
    int main()
    {
        int n;
       
        while(scanf("%d",&n),n>0)
        {
          if(n==0)
            continue;
          memset(mark,0,sizeof(mark));
         
          int i,a;
          for(i=0;i<n;i++)
             scanf("%d",&s1[i]);
          for(i=0;i<n;i++)
             scanf("%d",&s2[i]);
          int t=s2[0];
          printf("%d\n",t);
          int count=0;
          while(s1[count]!=t)
          {
               mark[s1[count]]=-1;
               count++;
          }
          int ii;
          for(ii=1;ii<n;ii++)  
          {
              int m=s2[ii];
              if(mark[m]==0)
              {
                 int i;
                 printf("%d\n",m);
                 for(i=count-1;s1[i]!=m;i++)
                 {
                     mark[s1[i]]=-1;
                 }
              }
          }
        }
    }

  • 相关阅读:
    判断具有某个属性js、jQuery
    新建maven项目,JRE System Library[J2SE-1.5]
    maven多模块搭建
    The POM for * is invalid
    【react】react-bookManager
    【cml】wosi-demo
    关于白盒测试
    【weex】h5weex-example
    【weex】publishTask
    Eslint报错的翻译
  • 原文地址:https://www.cnblogs.com/dchipnau/p/4985946.html
Copyright © 2011-2022 走看看