|
'跑到15*8已经很吃力了,,,
Option Explicit
Const X = 15, Y = 3 '15*3
Sub test()
Dim i, j, k, n, t, tm
ReDim arr(1 To X), brr(1 To X, 1 To Y), dic(X)
For i = 1 To X
arr(i) = i
Next
For j = 1 To Y
Set dic(j) = CreateObject("scripting.dictionary")
If j = 1 Then
For i = 1 To X
n = Int(Rnd * (X - i + 1)) + i
t = arr(i): arr(i) = arr(n): arr(n) = t: brr(i, j) = arr(i)
If i > 1 Then dic(j)(arr(i - 1) & "-" & arr(i)) = 1
Next
Else
tm = Timer
For i = 1 To X
n = Int(Rnd * (X - i + 1)) + i
t = arr(i): arr(i) = arr(n): arr(n) = t: brr(i, j) = arr(i)
For k = 1 To j - 1
If brr(i, k) = brr(i, j) Then i = i - 1: Exit For
If i > 1 Then
If dic(k).exists(arr(i - 1) & "-" & arr(i)) Then i = i - 1: Exit For
End If
Next
If k = j And i > 1 Then dic(j)(arr(i - 1) & "-" & arr(i)) = 1
If Timer - tm > 0.01 Then j = 1: Exit For
DoEvents
Next
End If
Next
[a1].Resize(X, Y) = brr
End Sub |
评分
-
1
查看全部评分
-
|