zoukankan      html  css  js  c++  java
  • 桶排

    桶排,顾名思义,就是开一个数组,包含所有在n的范围内的数,将每一个输入的数x加到对应到数组a[x]中,最后一起输出。

    桶排的时间复杂度为O(N)

    模板如下:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<cctype>
    #include<cmath>
    #include<cstdlib>
    #include<queue>
    #include<ctime>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    using namespace std;
    int a[100000];
    int main()
    {     int n,m,i,j,x,maxn=-1;
          cin>>n;
          for(i=1;i<=n;i++){
              cin>>x;
              a[x]++;
              maxn=max(maxn,x);
          }
          for(i=0;i<=maxn;i++)
             while(a[i]){
               cout<<i<<' ';
               a[i]--;
             }
          return 0;
    }

     

  • 相关阅读:
    【CSS】 布局之圣杯布局
    PHP函数
    spry菜单栏(二)
    正则表达式补充
    练习用php做表格
    PHP入门
    MySQL常用函数
    数据库习题
    总结
    Navicat
  • 原文地址:https://www.cnblogs.com/yzxverygood/p/7719630.html
Copyright © 2011-2022 走看看