Counting Sort 计数排序适用于数据量很大,但是数据类别很少的情况,可以做到线性时间。 举例来看:如果有100万个字符串,但只有cat, dog, person三种类型,采用基于比较的排序方式,可以做到$NlogN$,计数排序采用了一种完全不同的思想: 新建一个counts[3],记录每种 ...
分类:
其他好文 时间:
2020-06-24 10:31:57
阅读次数:
52
类似于保留几位小数,直接 n.toStringAsFixed()例如:1.toStringAsFixed(3); // 1.000(4321.12345678).toStringAsFixed(5); // 4321.123461000000000000000000000.toStringAsFix ...
分类:
其他好文 时间:
2020-06-16 23:07:35
阅读次数:
247
题意:给一个已知进制的数N1,问另一个数N2是否存在某一进制表示和N1相等。 思路(debug历程):将N1转化成10进制数,枚举进制计算N2,与N1进行比较。 先开始想到的是从2开始向上枚举到36,后来发现36不对。发现枚举上界应该是N1+1(这个看网上的证明吧https://blog.csdn. ...
分类:
其他好文 时间:
2020-06-14 14:39:17
阅读次数:
53
超级有用。 function stringToEntity(str,radix){ let arr=str.split('') radix=radix||0 let tmp=arr.map(item=> `&#${(radix?'x'+item.charCodeAt(0).toString(16): ...
分类:
Web程序 时间:
2020-06-10 09:14:39
阅读次数:
121
#include<stdio.h> #include<stdlib.h> void print_arr(int arr[],int N) { int i; for(i=0;i<N;i++) { printf("%d ",arr[i]); } } void radix_sort(int A[],int ...
分类:
编程语言 时间:
2020-06-03 17:36:42
阅读次数:
76
题目 Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes, if 6 is a decimal number and 110 i ...
分类:
其他好文 时间:
2020-05-19 01:04:00
阅读次数:
58
基数排序(radix sort): 对个位数先排序,再对十位数排序,以此类推。。 如果数据不满足位数相同,要对不够位数的数字前面补0(或者做类似处理)。 时间复杂度O(nk)其中n为数字个数,k为最多的数字位数。 void RadixSort(vector<int>& nums){ int maxD ...
分类:
编程语言 时间:
2020-05-14 09:13:43
阅读次数:
87
To illustrate the radix sort algorithm we will sort the sequence S0 = {32, 100, 11, 554, 626, 122, 87, 963, 265, 108, 9}. We start by distributing ele ...
分类:
其他好文 时间:
2020-05-01 00:45:46
阅读次数:
56
The base (or radix) of a positional numeral system is the number of symbols that can be used to represent a number in that system. The base 1010 syste ...
分类:
其他好文 时间:
2020-04-20 11:47:10
阅读次数:
74
/* * 基数序 解决不能负数的问题 */ public static void negative_radix_sortin(int[] str) { // 桶 10个桶 每个桶的最大容量默认为数组长度 int[][] bucket = new int[10][str.length]; // 每个桶 ...
分类:
编程语言 时间:
2020-04-11 23:47:10
阅读次数:
206