Title Link: http://poj.org/problem?id=1017
| Limit: 1000MS |
|
Memory Limit: 10000K |
| Total Submissions: 44985 |
|
Accepted: 15208 |
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 is always delivered to customers in the square parcels of the same height h as the products has and of th E size 6*6. Because of the expenses it is the interest of the factory as well as a 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 of money. You is asked to make such a program.
Input
The input file consists of several lines specifying orders. Each line specifies one order. Orders is 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 to which the order from the corresponding line of the input file can Packed. There is no line with the output file corresponding to the last "null" line of the input file.
Sample Input
Sample Output
Source
Approximate test instructions: A factory with 6 different size packaging to packaging products, respectively, h*1*1, h* 2*2, H*3*3, H*4*4, h*5*5, h* 6*6; (This place H can default to 1, no impact) I'm going to use a h*6 now. *6 's big box wraps these products together, so what's the minimum number of large boxes to ask? (That is, many small boxes are placed in a large box, requiring a minimum number of large boxes)
Test Instructions Analysis: (1) If the size of the small box is 6*6, then it must occupy a completely large box, right?
(2) If the size of the small box is 5*5, it also has to occupy a large box, but there will be more out of the place, you can analyze the more out of this part can only put 1*1 small box
(3) If the size of the small box is 4*4, then it has to occupy a large box, the extra one can put 5 small boxes of 2*2 size, and 7 1*1 small boxes
(4) If the size of the small box is 3*3, the local score is discussed, the size of the small box of 3*3 to 4, observe the remainder to know how the rest of the distribution
There is another place to note: 2*2 can be placed in a position must be able to place 4 1*1, but 4 1*1 can be placed in a place that does not necessarily place 1 2*2 small boxes;
#include <iostream> #include <stdio.h> #include <string> #include <string.h> #include < Algorithm>using namespace Std;int main () {int a,b,c,d,e,f; while (scanf ("%d%d%d%d%d%d", &a,&b,&c,&d,&e,&f)!=eof) {if (a+b+c+d+e+f==0) break; int cnt=0,tmp=0; Cnt+=f; Statistics of how many 6*6 box cnt+=e; a-=e*11;//statistics How many 5*5 box, at the same time the remaining space into 1*1 Cnt+=d; Count the number of 4*4 boxes and convert the remaining space to 2*2 if (b>=d*5) b-=d*5; else {tmp+=d*5-b,b=0;} if (c%4 = = 0) Cnt+=c/4; else {cnt+=c/4+1; c=c%4;} if (c==3) {a-=5; if (b>=1) b-=1; else if (b<=0) {tmp+=1;} } else if (c==2) {a-=6; if (b>=3) b-=3; else if (b<=0) tmp+=3; else {tmp+=3-b,b=0;} } else if (c==1) {a-=7; if (b>=5) b-=5; else if (b<=0) tmp+=5; else {tmp+=5-b,b=0;} } if (b>0) {if (b%9 = = 0) cnt+=b/9; else {cnt+=b/9+1; a-= (36-(b%9)); }} a-=tmp*4; if (a>0) {if (a%36 = = 0) cnt+=a/36; else { cnt+=a/36+1; }} printf ("%d\n", CNT); } return 0;}
POJ 1017 Packets Greedy Box placement problem