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;
    }
    
  • 相关阅读:
    活动安排
    中国剩余定理
    欧拉回路
    单词游戏
    Ant Trip
    John's Trip
    太鼓达人
    相框
    原始生物
    Blockade
  • 原文地址:https://www.cnblogs.com/nonames/p/12286098.html
Copyright © 2011-2022 走看看