以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 算法理论与分析 』 (http://bbs.xml.org.cn/list.asp?boardid=60) ---- 产生随机不重复数的算法复杂度 (http://bbs.xml.org.cn/dispbbs.asp?boardid=60&rootid=&id=43250) |
-- 作者:efme -- 发布时间:2/13/2007 10:29:00 AM -- 产生随机不重复数的算法复杂度 Unum=Request("Unum") Lnum=Request("Lnum") If Isnumeric(Unum) and Isnumeric(Lnum) Then Upperbound=Unum Lowerbound=Lnum Else Upperbound=100'设定初始值上界 Lowerbound=1'设定初始值下界 End If Dim MyArray()'设定动态数组,如果事先知道数组大小可直接设定大小值 ReDim Myarray(Upperbound)'定义动态数组的大小 For i=Lowerbound To Upperbound'将Lowerbound与Upperbound之间的数顺序写入数组中 Myarray(i)=i Next For i=Upperbound To Lowerbound step -1'随机取数 Randomize'初始化 Tmp=Int((i - Lowerbound + 1) * Rnd + Lowerbound)'动态地改变随机数的大小 Nnum=Myarray(Tmp)'取得当前已经获取的值 Myarray(Tmp)=Myarray(i)'将数组的最后一个值填入已取的位置,使前i个值永不重复 Response.Write(Nnum&"<br>")'输出结果 Next
以上算法的时间得杂度及空间得杂度是多少? |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
5,132.813ms |