Dim dd(0 To 100) As Integer '记录所有订单的取件距离
Dim fp(0 To 100) As Integer '存储第x个快递员取件的最远距离
Dim xs(0 To 100) As String
Private Sub Command1_Click()
Dim n As Integer,i As Integer,k As Integer,s As String
Dim left As Integer,right As Integer,m As Integer
Dim x As Integer,r As Integer
Randomize
s = Text1.Text: n = 1: i = 1
Do While i <= Len(s)
k = i: ch = Mid(s, k, 1)
Do While
k = k + 1: ch = Mid(s,k,1)
Loop
dd(n) = Val(Mid(s,i,k - i))
i = k + 1: n = n + 1
Loop
x = 1: fp(x) = dd(1)
For i = 2 To n - 1
left = 1
right = x
Do While left <= right
m = (left + right) \ 2
If Then
right = m - 1
Else
left = m + 1
End If
Loop
fp(r) = dd(i)
If r = x + 1 Then x = x + 1
Next i
Label2.Caption = "第" + Str(i - 1) + "件快递将由第" + Str(r) + "号快递员收取"
'列表框List1中显示每位快递员的收取情况,代码略
End Sub