小李编写 VB 程序实现上述功能:在列表框 List1 中按货物顺序显示其重量和货架号,在文本框Text1 中输入机器人送货趟数,单击“结果”按钮 Command1 后,标签 Label3 和 Label4 中分别显示要求机器人可承受的最大载重最小值和送货总行程。程序运行界面如图 b 所示。

图 a

图 b
请回答下列问题:
(1)如图 b 所示,机器人最大载量达到 20 时,机器人第 3 趟配送的货物数量是____件。
(2)实现机器人送货功能的 VB 程序如下,请在划线处填入合适的代码。
Const num = 8 '货物数量
Const shelf = 10 '货架数量, 1-9 号货架可供存储货物,第 10 号货架用作机器人装货点
Dim g(1 To num) As Integer '各货物的重量
Dim s(1 To num) As Integer '各货物的货架号
Private Sub Form_Load()
'从数据库中读入 num 件物品的重量、货架号,分别存储在数组 g、s 中
'将各物品数据显示在list1 中,代码略.
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, n As Integer, max As Integer, total As Integer
Dim head As Integer, tail As Integer, dis As Integer, part As Integer
①______
total = g(1)
For i = 2 To num
If g(i) > max Then max = g(i)
total = total + g(i)
Next i
n = 0
For i = max To total
part = 0: n = 0: head = 1: dis = 0
For j = 1 To num
part = part + g(j)
If part > i Then
n = n + 1: j = j - 1: tail = j
dis = dis + tran(head, tail)
part = 0: head = tail + 1
End If
Next j
If part > 0 Then
n = n + 1
②___
dis = dis + tran(head, tail)
End If
If n <= Val(Text1.Text) Then Exit For
Next i
Label3.Caption = "机器人可承受的最大载量至少为:" + Str(i)
Label4.Caption = "机器人完成各趟任务的总行程为:" + Str(dis)
End Sub
Function tran(p As Integer, q As Integer) As Integer '计算机器人每趟按装货倒序配送并回到A 处的行程
Dim temp As Integer, t1 As Integer, t2 As Integer, k As Integer
temp = 0: t2 = shelf
For i = q To p Step -1
t1 = t2: t2 = s(i)
k =③_____
If k > (shelf + 1) \ 2 Then k = shelf - k
temp = temp + k
Next i
If t2 <= shelf \ 2 Then temp = temp + t2 Else temp = temp + shelf - t2
tran = temp
End Function

同类型试题

y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2


y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2

