首页 > 代码库 > POJ 1017 Packets

POJ 1017 Packets

Packets
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 51871 Accepted: 17612

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 customers 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 would 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 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 

Source

Central Europe 1996
 
 
 
 1 #include <iostream> 2 #include <algorithm> 3 #include <map> 4 #include <vector> 5 #include <functional> 6 #include <string> 7 #include <cstring> 8 #include <queue> 9 #include <stack>10 #include <set>11 #include <cmath>12 #include <cstdio>13 using namespace std;14 #define IOS ios_base::sync_with_stdio(false)15 typedef long long LL;16 const int INF = 0x3f3f3f3f;17 const double PI=4.0*atan(1.0);18 19 LL ans;20 int c1,c2,c3,c4,c5,c6;21 int main()22 {23     while(scanf("%d%d%d%d%d%d",&c1,&c2,&c3,&c4,&c5,&c6)==6){24         if(c1+c2+c3+c4+c5+c6==0)return 0;25         ans=0;26         ans+=c6+c5;27         c1-=c5*11;28         if(c4>0){29             ans+=c4;30             int num=c4*5;31             if(c2>num) c2-=num;32             else c1-=(num-c2)*4,c2=0;33         }34         ans+=c3/4;35         c3%=4;36         if(c3!=0) ans++;37         if(c3==1){38             if(c2>=5){39                 c2-=5;40             }else{41                 c1-=20-c2*4;42                 c2=0;43             }44             c1-=7;45         }else if(c3==2){46             if(c2>=3) c2-=3;47             else{48                 c1-=12-c2*4;49                 c2=0;50             }51             c1-=6;52         }else if(c3==3){53             if(c2>0) c2--;54             else c1-=4;55             c1-=5;56         }57         if(c1<0) c1=0;58         if(c2>0){59             ans+=c2/9;60             if(c2%9){61                 ans++;62                 c1-=36-(c2%9)*4;63             }64         }65         if(c1>0){66             ans+=c1/36;67             if(c1%36) ans++;68         }69         printf("%lld\n",ans);70     }71     return 0;72 }

 

POJ 1017 Packets