Poj-1017-packet (greedy 1)

Source: Internet
Author: User

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

#include <stdio.h>intcnt2[4]= {0,5,3,1};intMain () {intd[Ten];  while(SCANF ("%d%d%d%d%d%d", &d[1],&d[2],&d[3],&d[4],&d[5],&d[6]) &&d[1]+d[2]+d[3]+d[4]+d[5]+d[6])    {        intn=0; N+=d[6]+d[5]+d[4]+ (d[3]+3)/4;//a 6*6 box can only fit up to 4 3*3 boxes.//when d[3] is equal to 5, take another box 5 plus three additional seats for 4 except for the two.        intd2=d[4]*5+cnt2[d[3]%4];//D[3] for the four-take-over range of 0 to 311 corresponding to the above-found rule        if(d2<d[2]) {n+ = (d[2]-d2+8)/9;//when there's more than 9 10+8/9=2, you need two more boxes .        }        intd1=n* $-d[6]* $-d[5]* --d[4]* --d[3]*9-d[2]*4; if(d1<d[1]) {n+ = (d[1]-d1+ *)/ $; } printf ("%d\n", N); }    return 0;}

Poj-1017-packet (greedy 1)

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.