题目
The numbers in the list below represent the weights, in kilograms, of ten crates. The crates are to be transported in trucks that can each hold a maximum total crate weight of 300 kg.
(a) Calculate a lower bound for the number of trucks that will be needed to transport the crates.
(b) Using the list provided, carry out a bubble sort to produce a list of the weights in descending order. You need only give the state of the list after each pass.
(c) Use the first-fit decreasing bin packing algorithm to allocate the crates to the trucks.
题目中文翻译
下面列表中的数字代表十个板条箱的重量(单位:千克)。板条箱将用卡车运输,每辆卡车最多可容纳总板条箱重量为 300 kg。
(a) 计算运输板条箱所需卡车数量的下界。
(b) 使用提供的列表,执行冒泡排序以产生降序的重量列表。只需给出每次传递结束后的列表状态。
(c) 使用首次适应递减装箱算法将板条箱分配给卡车。
解答
(a)
解法一
思路
展开
先求十个板条箱的总重量,再除以每辆卡车的最大载重。由于卡车数量必须是整数,所得商要向上取整;只写整数 4 而不展示这个计算,并不能充分说明下界的来源。
答题过程
展开
The total weight of the crates is
Hence
Therefore the lower bound for the number of trucks is
(b)
解法一
思路
展开
按照降序冒泡排序的比较方向逐趟扫描,相邻两数顺序不合要求时交换。题目只要求每一趟结束后的列表;即使第五趟已经得到有序列表,仍要再做一趟并写出没有发生交换的结果,才能确认排序结束。
答题过程
展开
The states of the list after successive passes are:
| Pass | State of list |
|---|---|
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 |
There are no swaps in pass 6, so the sort is complete.
(c)
解法一
思路
展开
使用 (b) 的降序列表依次放置板条箱。每次都从第一辆卡车开始检查,把当前板条箱放入第一辆仍有足够剩余容量的卡车;只有现有卡车都放不下时才启用新卡车。
答题过程
展开
Applying first-fit decreasing to
gives
| Truck | Crates (kg) | Total (kg) |
|---|---|---|
| 1 | 300 | |
| 2 | 300 | |
| 3 | 285 | |
| 4 | 265 |
Thus the crates are allocated to .