//intput array A,output array result.   count array count .

//all the elements is in te range of 0~k.

//if k=O(n),the complexity is Θ(n)

//counting sort is stable

for(i=0;i<n;i++)result[i]=0;

for(i=1;i<=n;i++)count[a[i]]++;

for(i=1;i<=n;i++)count[i]+=count[i-1];

for(j=n;j>1;j--)

{

result[count[A[j]]]=A[j];

count[A[j]]--;

}

/radix sort

//对每一位数字进行排序,收集后,递归进行,直到全部排序完成

//bucket sort

//按区间分布bucket,bucket内部使用insert sort.

CLRS:sorting in linear time O(n)的更多相关文章

  1. (转)Awesome Courses

    Awesome Courses  Introduction There is a lot of hidden treasure lying within university pages scatte ...

  2. [Algorithm] 如何正确撸<算法导论>CLRS

    其实算法本身不难,第一遍可以只看伪代码和算法思路.如果想进一步理解的话,第三章那些标记法是非常重要的,就算要花费大量时间才能理解,也不要马马虎虎略过.因为以后的每一章,讲完算法就是这样的分析,精通的话 ...

  3. hdu.5195.DZY Loves Topological Sorting(topo排序 && 贪心)

    DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  4. Chpater 10: Sorting

    Internal Sort: Bubble  O(n2) Selection O(n2) Insertion O(n2) Shell O(nlogn) Merge O(nlogn) Heap O(nl ...

  5. Topological Sorting

    Topological sorting/ ordering is a linear ordering of its vertices such that for every directed edge ...

  6. 排序算法(sorting)

    学习到的排序算法的总结,包括对COMP20003中排序部分进行总结,部分图片来自COMP20003 有部分内容来自http://www.cnblogs.com/eniac12/p/5329396.ht ...

  7. hdu 5195 DZY Loves Topological Sorting (拓扑排序+线段树)

    DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  8. hdu 5195 DZY Loves Topological Sorting 线段树+拓扑排序

    DZY Loves Topological Sorting Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...

  9. hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

随机推荐

  1. java: org.luaj.vm2.LuaError:XXX module not found lua脚本初始化出错

    我遇到这个错误是因为在引用脚本目录时,设置错了位置.设置成脚本所在目录的上级目录. lua使用和加载初始化方法 在java中使用lua,使用需要引用 luaj-jse-2.0.2.jar 同时需要使用 ...

  2. CF 161D Distance in Tree 树形DP

    一棵树,边长都是1,问这棵树有多少点对的距离刚好为k 令tree(i)表示以i为根的子树 dp[i][j][1]:在tree(i)中,经过节点i,长度为j,其中一个端点为i的路径的个数dp[i][j] ...

  3. linux命令(13) 删除指定文件夹下后缀名相同的文件

    方法一: find 目录 -name "*.abc" | xargs rm命令有点危险,可以先执行前半段,看看是不是你要删除的文件, 然后再整条执行 方法二:find . -nam ...

  4. 无状态服务(stateless service)

    一.定义 无状态服务(stateless service)对单次请求的处理,不依赖其他请求,也就是说,处理一次请求所需的全部信息,要么都包含在这个请求里,要么可以从外部获取到(比如说数据库),服务器本 ...

  5. RadASM中文乱码问题解决方法!!

    RadASM版本:2.2.2.0 在这个版本的RadASM代码编辑器里面,如果输入中文,则会乱码,经过一些尝试后,终于解决了这个问题,通过修改RadASM的字体设置就可以了!! 修改字体说明:通过本人 ...

  6. Memcached常用命令及使用说明(转)

    一.存储命令 存储命令的格式: 1 2 <command name> <key> <flags> <exptime> <bytes> < ...

  7. 九度OJ1061

    //C++ sort函数的多重排序 #include <iostream> #include<algorithm> #include<string> using n ...

  8. bat操作数据库mysql

    createDB.bat文件内容: @echo off cd C:/Program Files/cl_ZWL_App/<a href="http://lib.csdn.net/base ...

  9. MongoDB 多条件组合查询

    组合条件查询json格式语法 { "$and": [ { "Date": { $gt: ISODate("2015-06-05T00:45:00.00 ...

  10. POJ 2104 【主席树】【区间第K大】

    #include<stdio.h> #include<algorithm> #include<string.h> #define MAXN 100010 #defi ...