Problem Description
A factory
produces products packed in square packets of the same height h and
of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These products are
always delivered to customers in the square parcels of the same
height h as the products have and of the size 6*6. 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 1*1 to the biggest size 6*6. 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.
Sample Input
0 0 4 0 0
1
7 5 1 0 0
0
0 0 0 0 0
0
Sample Output
2
1
题意:有六种规格的货物,1*1, 2*2 ,3*3, 4*4 ,5*5
,6*6装货物的箱子只有6*6的,求用的最小箱子数;
解题思路:刚开始还以为箱子都是立体的,***(自己体会)!,写到装3*3的时候就不会写了,今早上一看题,才发现昨晚自己瞎了,既然是二维的就好做了,假期看的书里有过这到题,当时看了一点,有点印象,从6*6到1*1贪心,6
,5 ,4的只能装一个,5 的还能装1的,4的还能装1 2的,3的比较麻烦能装1 2 3的,一个个的讨论,剩下1
2的,判断是否大于零就行了,因为装起来比较简单;
感悟:这道题做完比较有成就感,因为测试了很多数据,一个个的BUG改,真爽啊;
测试数据:
Input:
0 0 4 0 0 1
7 5 1 0 0 0
36 9 4 1 1 1
0 9 4 1 1 0
0 0 4 0 0 0
36 0 0 0 0 0
0 9 0 0 0 0
79 96 94 30 18 14
53 17 12 98 76 54
83 44 47 42 80 3
15 26 13 29 42 40
41 61 36 90 54 66
78 56 445 45 23 65
13 4 8 29 45 3
15 75 45 98 34 53
40 9 0 2 0 0
41 9 0 2 0 0
44 0 0 0 4 0
0 2 3 0 0 0
37 7 2 0 1 0
12 2 0 1 0 0
13 2 0 1 0 0
0 0 0 0 0 0
Output:
2
1
6
4
1
1
1
86
231
137
115
219
245
79
197
3
4
4
2
3
1
2
0 0 4 0 0 1
7 5 1 0 0 0
36 9 4 1 1 1
0 9 4 1 1 0
0 0 4 0 0 0
36 0 0 0 0 0
0 9 0 0 0 0
79 96 94 30 18 14
53 17 12 98 76 54
83 44 47 42 80 3
15 26 13 29 42 40
41 61 36 90 54 66
78 56 445 45 23 65
13 4 8 29 45 3
15 75 45 98 34 53
40 9 0 2 0 0
41 9 0 2 0 0
44 0 0 0 4 0
0 2 3 0 0 0
37 7 2 0 1 0
12 2 0 1 0 0
13 2 0 1 0 0
0 0 0 0 0 0
Output:
2
1
6
4
1
1
1
86
231
137
115
219
245
79
197
3
4
4
2
3
1
2
代码:
#include
#include
#include
using namespace std;
int main()
{
//freopen("in.txt", "r", stdin);
int
ans[7]={0},sizen[7]={0,1,2,3,4,5,6};
int
null=0;
while(~scanf("%d%d%d%d%d%d",&ans[1],&ans[2],&ans[3],&ans[4],&ans[5],&ans[6]))
{
if(ans[1]==0&&ans[2]==0&&ans[3]==0&&ans[4]==0&&ans[5]==0&&ans[6]==0)
break;
null=0;
null+=ans[6];//因为装了6*6的就没有别的空间了;
#include
#include
using namespace std;
int main()
{