Link:
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_ problem&problem=247
Original title:
A Factory produces products packed in square packets of the same height H and of the sizes,,,,,. These products are are always delivered to customers in the square parcels of the same height H as the products have and of th E size. Because of the expenses it is the interest of the factory as as "the" the customer to minimize the number of parcels NEC Essary 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 accord ing to an order would save a lot. You are are asked to make such a.
Input
The input file consists of several lines specifying orders. Each line specifies the 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 to the biggest size. The "End of" 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 to which the order from the corresponding line of the input file can Packed. There is no. 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
The main effect of the topic:
Boxes with 1*1,2*2,3*3,4*4,5*5,6*6 sizes are packed in 6*6 boxes, and their height is the same. Use the least 6*6 box to load all sizes of boxes.
Analysis and Summary:
The problem is that I am in Volume 4. Algorithm design the last thing to do in this topic, mainly because there is no train of thought. It's best to refer to other people's ideas.
This column more highlights: http://www.bianceng.cn/Programming/sjjg/
6*6 boxes can be filled with boxes of various sizes. These conditions can be as follows:
1 a 6*6
1 5*5+11, a 1*1.
1 4*4+5 a 2*2 (priority to place the 2*2 if there is a gap, if the 2*2 is not finished, the rest will be placed 1*1)
When placing 3*3, the composition is more complex. When the 3*3 is not finished, the remaining voids are also given priority to placing 2*2 as much as possible. When you place 1 3*3, you can also place 7 1*1 and 5 2*2 when you place 2 3*3, you can also place 6 1*1 and 3 2*2 when you place 3 3*3, and you can also place 5 1*1 and a 2*2
Because a 4*4,5*5,6*6 can only be placed in a box, so how many of these, it will take how many boxes to install.
Then because the 3*3 can be placed in combination with the 1*1 and 2*2, it is also possible to determine the boxes that are needed to complete the 3*3.
Then in the calculation, first you can determine the number of 3*3,4*4,5*5,6*6 boxes, assuming that the T box.
Then there is a void in the T box, and the 2*2 is placed in the void in the T box. If these voids do not finish 2*2, then you need to add the box to know the end. Finally, consider placing the 1*1.
Code:
* * * uva:311-packets * time:0.008s * Author:d_doubel * * * * * * */#include <iostream> #include <cstdio>
;
using namespace Std;
int arr[7]; Placing 3*3 in 6*6, placing more 2*2//When placing 1 3*3, you can also place 7 1*1 and 5 2*2///When you place 2 3*3, you can also place 6 1*1 and 3 2*2//When 3 3*3 are placed, you can also place 5 1*1 and 1
A 2*2 int three[4][2]= {0,0},{7,5},{6,3},{5,1}}; int main () {while (~scanf ("%d%d%d%d%d%d", &arr[1],&arr[2],&arr[3],&arr[4],&arr[5],&arr[6])
{if (!arr[1]&&!arr[2]&&!arr[3]&&!arr[4]&&!arr[5]&&!arr[6]) break; int ans= (arr[3]+3)/4+arr[4]+arr[5]+arr[6]; 3*3,4*4,5*5,6*6 together with several arr[1]-= arr[5]*11; 6*6 can place a 5*5 and 11 1*1, so directly prioritize 1*1 and 5*5 in a box where the space in the box int left_for_2=three[arr[3]%4][1]+arr[4]*5;//has used can also be put How many 2*2 if (arr[2]<=left_for_2) {//when the voids in the box can be placed in the 2*2 box arr[1]-= three[arr[3]%4][0]; Number of 1*1 that can be placed with 2*2 in the void arr[2] =left_for_2; ARR[1] + = arr[2]*4; If 2*2 is a negative number, it means that the absolute value of the negative number is void and can be used to place the 1*1 if (arr[1]>0)//If 1*1 Also, then add the box ans + + (arr[1]+35)/3
6; } else{///Cannot place 2*2 arr[1]-= three[arr[3]%4][0];//Before and 2*2 together fill the box 1*1 arr[2] = l
eft_for_2; Ans + + (arr[2]+8)/9; Add the box until you can finish 2*2 arr[1]-= (9-arr[2]%9) *4;
The added box may not fill up the 2*2, and there is room for 1*1 if (arr[1]>0) ans + = (arr[1]+35)/36;
printf ("%d\n", ans);
return 0; }