这题对于O(n^2)的算法有很多,我这随便贴一个烂的,跑了375ms。

#include<iostream>
#include<algorithm>
using namespace std;
int mat[8008];
int main()
{
    int i,j,t,n;
    scanf("%d",&n);
    
         mat[0]=1;
         for(i=1;i<n;i++) 
         {
             scanf("%d",&t);
             mat[i]=t+1;                    
             for(j=0;j<i;j++)                       
               if(mat[j]>=mat[i])
                {  mat[j]++;}
         }
         for(i=0;i<n;i++)
            printf("%d\n",mat[i]);
    
    return 0;
}    
View Code

相关文章:

  • 2021-10-26
  • 2021-05-16
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2021-11-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
  • 2022-01-09
  • 2021-06-15
  • 2021-10-15
相关资源
相似解决方案