Poj 1017 packets (Greedy)

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

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 lot of 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 packages of individual size from
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 

Source

Central Europe 1996 Question:There are 1*1, 2*2, 3*3, 4*4, 5*5, 6*6 items, the shipping company uses 6*6 boxes, it is required to put all items in the box and how to minimize the number of items in the box.
Analysis:First, the analysis: each 4*4, 5*5, 6*6 item requires a 6*6 box. The remaining space can be used to hold small items. The remaining space of the 5*5 box can be loaded with 11 1*14*4 boxes. The remaining space can be loaded with 5 2*2 and several (no need to calculate, because the entire area can be used to calculate 1*1 space) A 1*16*6 box can be loaded with 4 3*3 so that in order to minimize the number of required boxes, in fact, our ideas also imply that we should First install large items
Count the number of boxes by rounded up Use area statistics to calculate 1*1 Vacancy
 Rounded up: the analogy is used to take the entire function up. In fact, it is to add + 1 on decimal A and then take the integer part,
That is, (a + 1)/1. Similarly, for 3*3 items, four boxes can be packed in a box (Box [3] + 3)/4
Code:
#include<cstdio>int t[4]={0,5,3,1};int box[7];int main(){    while(1)    {        int tmp=0,i;        for(i=1;i<=6;i++)        {            scanf("%d",&box[i]);            tmp+=box[i];        }        if(tmp==0)            break;        int ans=box[6]+box[5]+box[4]+(box[3]+3)/4;        int a2=box[4]*5+t[box[3]%4];        if(box[2]>a2)            ans+=((box[2]-a2)+8)/9;        int a1=ans*36-box[6]*36-box[5]*25-box[4]*16-box[3]*9-box[2]*4;        if(box[1]>a1)            ans+=(box[1]-a1+35)/36;        printf("%d\n",ans);    }    return 0;}

12012408

Fukan

1017

Accepted

164 K

16 Ms

C ++

595b

2013-08-20 08:32:32

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.