题目

老张要准备一道晚宴,需要上n个菜,为了省事他在n个不同的餐厅订好了这些菜。现在他需要尽快取回这些菜,对于每一道菜,有两种取菜方式: 1)让各店的外卖员送货上门,对于第i个菜需要花费a(i)的时间。 2)自己去餐厅取回家,每次出门仅能取回一道菜,对于第i个菜,从出门到回家整个过程需要花费b(i)的时间。 每家餐厅都有各自的外卖员送菜,并且无论老张是否在家,他们都能把菜送到。为了节省时间,能由外类员送的菜尽量由外卖负各自送达,现在需要知道最少花费多少时间能集齐所有的菜。 比如n=4,a(i)=(30,70,40,50),b(1)=(20,10,20,30},那么花费时间少的方案是第一个菜和第三个菜让让外卖员送,第二个菜和第四个菜老张自己取,一共需要40分钟。 设计VB程序计算最少时间,界面如下图 实现上述功能的VB程序如下,回答以下问题: (1) 根据程序语句判断对象Lab3属于类。 (单选,填字母:A .Form1/B .Label /C .TextBox / D .CommandButton) (2) 请在划线处填入合适的代码。 Const n=4 Dim a(1 To n) As Integer    'n道菜由每家餐厅外卖员送达耗时 Dim b(1 To n) As Integer    'n道菜自取耗时 Private Sub Form Load)     '产生外卖送货各道菜耗时,并存储到数组a中,并显示     '产生自取各道菜耗时,并存储到数组b中,并显示     '代码略 End Sub Private Sub Command1_Click()     Dim i As Integer, max As Integer, ans As Integer     Dim left As Integer, right As Integer, m As Integer     For i=1 To n         If a(i) > max Then       '外卖员送菜的最长时间     Next i     left= 1: right = max: ans = max     Do While left <= right         m= (left + right) \ 2         If Then             ans = m: right=m-1         Else             left=m+1         End If     Loop     Lab3. Caption=“最快”+ Str(ans) + “分钟” End Sub Private Function check(t As Integer) As Boolean     Dim total As Integer     check = False     For i =1 To n         If a(i) > t Then             total ='如果外卖来不及就自己取         End If     Next i   If  Then check = True End Function (3) 程序中加框处代码有错,请改正。 答案: 【1】B 【1】max=a(i)或其他等价答案【2】check(m) 或check (m) =true或其他等价答案【3】total + b(i)或其他等价答案 total <= t或其他等价答案
信息技术 试题推荐
最近更新