POJ 1017 Packets

发布时间:2014-10-22 18:17:09编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"POJ 1017 Packets",主要涉及到POJ 1017 Packets方面的内容,对于POJ 1017 Packets感兴趣的同学可以参考一下。

http://poj.org/problem?id=1017 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 题意就是将边长分别为1,2,3,4,5,6的盒子放入边长为6 的正方形箱子中,高均为H,可以不考虑,求用的最少箱子数。。。贪心 代码: #include <stdio.h> #include <string.h> #include <iostream> using namespace std; int main() { int p[]={0,5,3,1},a,b,c,d,e,f; while(~scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)) { if(a+b+c+d+e+f==0) break; int sum=0; sum+=(d+e+f); sum+=(c/4); if(c%4) sum++; int need2=(d*5+p[c%4]); if(need2<b) { sum+=((b-need2)/9); if((b-need2)%9) sum++; } int need1=sum*36-f*36-e*25-d*16-c*9-b*4; if(need1<a) { sum+=((a-need1)/36); if((a-need1)%36) sum++; } printf("%d\n",sum); } return 0; }


上一篇:资源类动规练习
下一篇:myGzoom--图片弹出层(仿windows照片查看器,可缩放抓取移动)

相关文章

关键词: POJ 1017 Packets

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款