Poj 1017 packets

Source: Internet
Author: User
Packets
Time limit:1000 ms   Memory limit:10000 K
Total submissions:43436   Accepted:14637

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 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 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 wocould save a of lot 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 


Analysis:
Packing problems, using greedy ideas, from the largest Installation
6x6, 5x5, and 4x4 each requires a box.
5x5 and 11x1, 4x4 and 5x2
3 × 3: 4 cases
1. Full
2. If one is left, five 2 × 2 and seven 1 × 1 are installed.
3. If two are left, 3 2x2 and 6 1x1 are installed.
4. If there are three, one 2 × 2 and five 1 × 1 are installed.
Additional 2X2, filled with 1x1 after installation
If 2 × 2 is not enough, the original 2 × 2 is filled with 1 × 1.


# Include <stdio. h >#include <iostream >#include <algorithm> using namespace STD; int P [4] = {,}; // After 3 × 3 is completed, after the rest is added to the new box, you can also put several 2 × 2 Packages (the subscript corresponds to the remainder) int main () {int A, B, C, D, E, F; int K1, K2, sum; while (CIN> A> B> C> D> E> F) {if (a = 0 & B = 0 & C = 0 & D = 0 & E = 0 & F = 0) break; sum = F + E + D + (C + 3)/4; // use a box for each of the 6*6, 5*5, 4*4, 3*3 rounded up to 4 k1 = D * 5 + P [C % 4]; // set 2*2 and 4*4 (3*3) put together, need 2*2 number if (k1 <B) sum + = (b-k1 + 8)/9; // separately put 2*2 in a box, requires 2*2 numbers k2 = sum * 36-b * 4-C * 9-d * 16-e * 25-f * 36; // requires 1*1 number if (K2 <) sum + = (a-k2 + 35)/36; // separate 1*1 put in a box, need 1*1 number cout <sum <Endl ;} 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.