zoukankan      html  css  js  c++  java
  • 桶排序

    https://www.cnblogs.com/bqwzx/p/11029264.html

    复杂度为O(n+m)。

    特点:消耗空间大最少需要max(数据范围的最大值)个桶去装,但时间时间复杂度是线性的O(n)。

    #include<bits/stdc++.h>
    #define me(x , y) memset(x , y , sizeof(x))
    #define SC scanf
    #define rep(i , j , n) for(int i = j ; i < n ; i ++)
    #define red(i , n , j) for(int i = n-1 ; i >= j ; i--)
    #define INF  0x3f3f3f3f
    #define mod 1000000007
    #define PI acos(-1)
    using namespace std;
    typedef long long ll ;
    int cnt[109];
    int a[109];
    int main()
    {
        int n , m = -1;cin>>n;
        rep(i , 0 , n) SC("%d" , &a[i]) , cnt[a[i]]++ , m = max(m , a[i]);
        rep(i , 0 , m+1){
            rep(j , 0 , cnt[i]){
                cout << i << endl;
            }
        }
        return 0;
    }
    
  • 相关阅读:
    php面向对象开发的学习
    我的php感悟
    说说面向对象
    session,上传文件
    PHP构造函数的用法分析
    生成图片
    上传文件
    fetch
    ajax2
    ajax1
  • 原文地址:https://www.cnblogs.com/nonames/p/12286098.html
Copyright © 2011-2022 走看看