POJ1017 box Filling

Source: Internet
Author: User

PacketsTime Limit: 1000 MS Memory Limit: 10000 KTotal Submissions: 38381 Accepted: 12817 DescriptionA 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 mers MERs 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 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 wocould save a of lot money. you are asked to make such a program. inputThe input file consists of several lines specif Ying 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. outputThe output file contains one line for each line in the input file. this line contains the minimal n Umber 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 Input0 0 0 0 0 1 7 5 1 0 0 0 0 0 0 0 0 Sample Output2 1 SourceCentral Europe 1996 general question: a factory-created product is in a rectangular box, their height is h, and the length and width are equal. There are six models in total: 1x1, 2x2, 3x3, 4x4, 5x5, 6*6. These products are usually packaged in a 6*6 * h rectangular box and then mailed to the customer. Because postage is very expensive, the factory has to find ways to reduce the number of boxes when each order is shipped BoxNum. Solution: Because the height of the box and box is h, you only need to consider the space of the bottom area. 6*6 boxes. Each box excludes one box. 5*5 boxes. Each box is placed in one box. The remaining space of the box can be 1*1 at most and 11 at most. 4*4 boxes. Each box is placed in one box. The maximum size of the remaining space of the box is 2*2. 3*3 boxes are exclusive to each 4 boxes, with less than 4 3*3 boxes. The remaining space is filled with 2*2 and 1*2. The 2*2 box and 1*1 box are mainly used to fill the remaining space of other boxes. The excess space after filling opens up new boxes for filling. [Cpp] # include <iostream> # include <cstdio> using namespace std; int main () {int p [4] = {,}, a [10]; // after the 3 × 3 package is completed, you can add the remaining package to the new box and put several 2 × 2 Packages (the subscript corresponds to the remainder) while (1) {int sum = 0; for (int I = 1; I <= 6; I ++) {scanf ("% d", & a [I]); sum + = a [I];} if (sum = 0) break; sum = 0; sum = a [4] + a [5] + a [6] + a [3]/4; if (a [3] % 4! = 0) sum ++; int need2 = a [4] * 5 + p [a [3] % 4]; if (need2 <a [2]) {sum + = (a [2]-need2)/9; if (a [2]-need2) % 9! = 0) sum ++;} int need1 = sum * 36-a [2] * 4-a [3] * 9-a [4] * 16-a [5] * 25-a [6] * 36; // The number of required 1 × 1, that is, the total area of all boxes minus the total area of the last 5 boxes if (need1 <a [1]) {sum + = (a [1]-need1)/36; if (a [1]-need1) % 36! = 0) sum ++;} printf ("% d \ n", sum);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.