Packing problem of greedy algorithm (c + +) __ algorithm

Source: Internet
Author: User

reproduced in http://blog.csdn.net/c20190413/article/details/77396357###;

Packing problem Description a factory-made product shapes are cuboid, their height is H, long and wide are equal, a total of six models, their long width is 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These products are usually packaged with a 6*6*h cuboid package and mailed to the customer. Because the postage is very expensive, the factory should find ways to reduce the number of parcels per order delivery. They need to have a good program to help them solve the problem and save money. Now this program is designed by you. The input file includes several lines, each representing an order. One line in each order consists of six integers, separated by spaces in the middle, and the number of six products 1*1 to 6*6 respectively. The input file ends with a line consisting of 6 0. Output In addition to the last line of input 6 0, each row in the input file corresponds to the output file row, each row of an integer to represent the corresponding order of the minimum number of packages required. Sample Input

0 0 4 0 0 1 7 5 1 0 0- 
0 
Sample Output
2 

SourceEurope 1996 Analysis of Ideas
Code Implementation [cpp]  View plain  copy #include <bits/stdc++.h>   using namespace std;    int p1,p2,p3,p4,p5,p6,sum;   Main ()    {       while ( scanf ("%d%d%d%d%d%d", &AMP;P1,&AMP;P2,&AMP;P3,&AMP;P4,&AMP;P5,&AMP;P6) &&p1+p2+p3+p4+p5+p6)        {           sum=0;            sum=p6+p5+p4;            p1-=min (p1,p5*11);           if (p2<p4*5)                p1-=min (P1, (P4*5-P2) *4);           p2-=min (p2,p4*5);            p5=p4=0;           sum+=ceil (p3/4.0);  &nBsp         p3%=4;            if (p3==1)            {                if (p2<5)  p1-=min (P1, (5-P2) *4);                p1-=min (p1,7);                p2-=min (p2,5);            }           if (p3==2)             {                if (p2<3)  p1-=min (P1, (3-P2) *4);                p1-=min (p1,6);                 p2-=min (p2,3);           }            if (p3==3)             {               if (!P2)  p1-= Min (p1,4);               p1-=min (p1,5);                p2-=min (p2,1);           }            Sum+=ceil (p2/9.0);           p2%=9;            if (p2)  p1-=min (p1,4* (9-P2));            sum+=ceil (p1/36.0);           printf ( "%d\n", sum);  &nbsp

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.