如果考虑顺序的话,每组第一个有12种可能,第二个11种,第三个10种,第四个9种,共A=1211109种;
现在不考虑顺序,当每组四个数确定了,假设是(5)(11)(12)(8),它有B=4321种顺序排列,故而共有A/B组
//B,C待合并的数组
//为了过程简单,可以在B,C最后各加一个哨兵
merge(B,C){
//定义一个新数组A,其长度为B,C长度之和
Alength=Blength+Clength;
B[Blength+1]=x;//x为一个小于所有元素的数
C[Clength+1]=x;
j=1;
k=1;
for(i=1;i<=Alength;i++){
if(j<=Blength && B[j]>C[k])
A[i]=B[j++];
else
A[i]=C[k++];
}
}(1)快速排序
6,5,9,12,20,31,24
5,6,9,12,20,31,24
5,6,9,12,20,24,31
辅助空间:最好log2n,最差n^2
不稳定
(2)二路归并排序
5,12,9,20,6,31,24
5,9,12,20,6,24,31
5,6,9,12,20,24,31
辅助空间:n
稳定
(3)堆排序
12,5,9,20,6,31,24
12,5,9,20,6,31,24
5,12,9,20,6,31,24
5,6,9,20,12,31,24
24,6,9,20,12,31 5
24,6,9,20,12,31 5
24,6,9,20,12,31 5
6,24,9,20,12,31 5
6,12,9,20,24,31 5
31,12,9,20,24 6 5
31,12,9,20,24 6 5
9,12,31,20,24 6 5
24,12,31,20 9 6 5
24,12,31,20 9 6 5
12,24,31,20 9 6 5
12,20,31,24 9 6 5
24,20,31 12 9 6 5
20,24,31 12 9 6 5
31,24 20 12 9 6 5
24,31 20 12 9 6 5
31 24 20 12 9 6 5
辅助空间:1
不稳定
(4)插入排序
5,12,9,20,6,31,24
5,9,12,20,6,31,24
5,9,12,20,6,31,24
5,6,9,12,20,31,24
5,6,9,12,20,31,24
5,6,9,12,20,24,31
辅助空间:1
稳定
(5)冒泡排序
5,9,12,6,20,24,31
5,9,6,12,20,24,31
5,6,9,12,20,24,31
5,6,9,12,20,24,31
辅助空间:1
稳定
选定A1:E11,输入
=RANDBETWEEN(1,13-COLUMN())
按Ctrl+Enter
A12=SUBSTITUTE("abcdefghijkl",MID("abcdefghijkl",A1,1),"")
下拉到A22
B12=SUBSTITUTE(A12,MID(A12,B1,1),"")
右拉到E12,再一起下拉到22行
F12=COUNTIF($E$12:$E$22,E12)
下拉到F22
在F1输入如下数组公式(用Shift+Ctrl+Enter输入):
=AND(F12:F22=1)
G12=INDEX({"03","04","09","10","15","18","19","21","22","24","28","29"},FIND(MID($E12,COLUMN(A1),1),"abcdefghijkl"))
右拉到M12,再一起下拉到22行
N12=G12&" "&H12&" "&I12&" "&J12&" "&K12&" "&L12&" "&M12
下拉到N22
这样每按一次F9,当F1显示TRUE时,N12:N22随机列出了11组不同的你要的组合,如图:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)