UVA 311 - Packets

链接:戳我

题目如下:

Packets

 

A factory produces products packed in square packets of the same height h and of the sizes tex2html_wrap_inline27 , tex2html_wrap_inline29 , tex2html_wrap_inline31 , tex2html_wrap_inline33 , tex2html_wrap_inline35 , tex2html_wrap_inline37 . These products are always delivered to customers in the square parcels of the same height h as the products have and of the size tex2html_wrap_inline37 . Because of the expenses it is the interest of the factory as well as of the customer to minimize the number of parcels necessary to deliver the ordered products from the factory to the customer. A good program solving the problem of finding the minimal number of parcels necessary to deliver the given products according to an order would save a lot of money. You are asked to make such a program.

Input

The input file consists of several lines specifying orders. Each line specifies one order. Orders are described by six integers separated by one space representing successively the number of packets of individual size from the smallest size tex2html_wrap_inline27 to the biggest size tex2html_wrap_inline37 . The end of the input file is indicated by the line containing six zeros.

Output

The output file contains one line for each line in the input file. This line contains the minimal number of parcels into which the order from the corresponding line of the input file can be packed. There is no line in the output file corresponding to the last ``null'' line of the input file.

 

解答:

装箱的方法如下:

1. 6 X 6:自己装一个箱子

2. 5 X 5:自己装一个箱子,剩余部分拿1 X 1的填充

3. 4 X 4:自己装一个箱子,剩余的部分拿5个2 X 2的填充,不够的话拿1 X 1的填充。

4. 3 X 3:首先,4个3 X 3的装一个箱子,装完之后如果还有余数,这个箱子分三种情况:

  1)还剩一个3 X 3:装5个2 X 2

  2)还剩两个3 X 3:装3个2 X 2

  3)还剩三个3 X 3:装1个2 X 2

  剩下的都拿1 X 1的填充。

5. 如果还有2 X 2的或1 X 1的,自己组团吧...

所以箱子的总数是:#(6X6) + #(5X5) + #(4X4) + ceiling of (#(3X3)/4) + parcels packeted by remaining 2X2 or 1X1 packets

 

posted @ 2013-03-19 22:16  frankdj  阅读(197)  评论(0编辑  收藏  举报