题目
Problem
The numbers listed below are to be packed into bins of size n, where n is a positive integer.
1420231715221925132832
A lower bound for the number of bins required is 4.
(a) Determine the range of possible values of n. You must make your method clear.
(3)
(b) Carry out a quick sort to produce a list of the numbers in descending order. You should show the result of each pass and identify your pivots clearly.
(4)
When the first-fit bin packing algorithm is applied to the original list of numbers, the following allocation is achieved.
Bin 1: 14202315
Bin 2: 17221913
Bin 3: 2528
Bin 4: 32
When the first-fit decreasing bin packing algorithm is applied to the sorted list of numbers, the following allocation is achieved.
Bin 1: 3228
Bin 2: 252322
Bin 3: 20191715
Bin 4: 1413
(c) Determine the value of n. You must explain your reasoning fully.
(3)
题目中文翻译
下面列出的数字要装入大小为 n 的箱子中,其中 n 是正整数。
1420231715221925132832
所需箱子数量的下界为 4。
(a) 确定 n 的可能取值范围。必须清楚说明方法。
(b) 执行快速排序以产生降序的数字列表。应显示每次传递的结果并清楚地标出枢轴。
当对原始数字列表应用首次适应装箱算法时,获得以下分配。
箱 1:14202315
箱 2:17221913
箱 3:2528
箱 4:32
当对排序后的数字列表应用首次适应递减装箱算法时,获得以下分配。
箱 1:3228
箱 2:252322
箱 3:20191715
箱 4:1413
(c) 确定 n 的值。必须完全解释推理过程。
解答
(a)
解法一
思路
展开
所有数的总和为 228。箱数下界为 4,表示总重量除以箱子容量后大于 3 且不超过 4。利用 n>0 解这个双重不等式,再结合 n 是正整数写出范围。
答题过程
展开
The total of the numbers is 228. Since the lower bound is 4,
3<n228≤4.
As n>0,
3n<228and228≤4n.
Therefore
n<76andn≥57.
Since n is an integer,
57≤n≤75.
(b)
解法一
思路
展开
采用 middle-right 规则选枢轴,并按降序排列:大于枢轴的数放在左侧,小于枢轴的数放在右侧。对每个尚未排好的子列表继续使用相同规则;竖线表示枢轴已经固定。
答题过程
展开
Using middle-right pivots, the initial pivot is 22.
23,25,28,32∣22∣14,20,17,15,19,13
Using pivots 28 and 15 gives
32∣28∣23,25∣22∣20,17,19∣15∣14,13.
Using pivots 25, 17 and 13 gives
32∣28∣25∣23∣22∣20,19∣17∣15∣14∣13.
Finally, using pivot 19 gives
32,28,25,23,22,20,19,17,15,14,13.
解法二
思路
展开
也可以一致地采用 middle-left 规则。第一次仍以 22 为枢轴;之后各子列表的枢轴选择会不同,但最终降序列表不变。
答题过程
展开
Using middle-left pivots, the initial pivot is 22.
23,25,28,32∣22∣14,20,17,15,19,13
Using pivots 25 and 17 gives
28,32∣25∣23∣22∣20,19∣17∣14,15,13.
Using pivots 28, 20 and 15 gives
32∣28∣25∣23∣22∣20∣19∣17∣15∣14,13.
Finally, using pivot 14 gives
32,28,25,23,22,20,19,17,15,14,13.
(c)
解法一
思路
展开
先用 first-fit 的 Bin 1 得到容量只能是 72 或 73:其中已有数的总和为 72,而先前尝试放入的 17 会令总和达到 74,所以它放不下。再看 first-fit decreasing 的 Bin 1,若容量是 73,最后的 13 应能与 32、28 同箱;实际没有放入,因此容量小于 73。两项条件合起来唯一可能是 72。
答题过程
展开
In the first-fit packing, Bin 1 contains
14+20+23+15=72,
so n≥72. The value 17 was considered before 15 but did not fit in Bin 1, and
14+20+23+17=74.
Hence n<74. Since n is an integer,
n∈{72,73}.
In the first-fit decreasing packing, Bin 1 contains 32 and 28, but the later value 13 does not fit there. Therefore
32+28+13=73>n,
so n<73. Combining the conditions,
n=72.