poj1017 Packets

参考了http://www.cnblogs.com/mycapple/archive/2012/08/23/2652070.html

思路:

贪心。

实现:

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4
 5 int main()
 6 {
 7     int b1, b2, b3, b4, b5, b6; //不同大小的木块个数
 8     int nTotal = 0;             //最少需要的箱子数目
 9     int c1;                        //当前能放 1*1 木块的空格数目
10     int c2;                        //当前能放 2*2 木块的空格数目
11     int Contain2[4] = { 0, 5, 3, 1 }; //记录被3*3的占用之后,还剩多少给2*2的使用
12     while (cin >> b1 >> b2 >> b3 >> b4 >> b5 >> b6, b1 || b2 || b3 || b4 || b5 || b6)
13     {
14         nTotal = b6 + b5 + b4 + (b3 + 3) / 4; //只能装1个6*6的,1个5*5的,1个4*4的,
15                                               //而3*3的需要多情况考虑,3*3的需要向上调整
16                                               //这里有一个小技巧 (b3+3)/4
17                                               //正好等于b3除以4向上取整的结果,下同
18         c2 = 5 * b4 + Contain2[b3 % 4]; //放2*2的数目等于放一个4*4时需要5个2*2加上
19                                         //放1到4个3*3时各需要的数目 ,即还可以装多少个2*2的
20         if (b2 > c2)
21             nTotal += (b2 - c2 + 8) / 9;  //向上调整 ,总的2*2的个数减去装过的2*2的个数,
22                                           //得到剩余的2*2的个数,
23                                           //此个数加上8然后除以9就正好等于它除以9向上取整的结果,
24                                           //之所以总数要加上这个数是由于若单独装2*2,可以装9个
25         c1 = 36 * nTotal - 36 * b6 - 25 * b5 - 16 * b4 - 9 * b3 - 4 * b2; //还可以装多少个1*1的
26         if (b1 > c1)
27             nTotal += (b1 - c1 + 35) / 36; //向上调整,总的1*1的个数减去装过的1*1的个数,
28                                            //得到剩余的1*1的个数,
29                                            //此个数加上35然后除以36就正好等于它除以36向上取整的结果
30                                            //之所以总数要加上这个数是由于若单独装1*1,可以装36个
31         cout << nTotal << endl;
32     }
33     return 0;
34 }
时间: 2024-10-23 18:18:21

poj1017 Packets的相关文章

POJ1017 Packets(贪心算法训练)

Time Limit: 1000MS          Memory Limit: 10000K          Total Submissions: 51306          Accepted: 17391 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 pro

POJ1017 Packets 【贪心】

Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44505   Accepted: 15032 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 alway

poj-1017 Packets (贪心)

http://poj.org/problem?id=1017 工厂生产高度都为h,长和宽分别是1×1 2×2 3×3 4×4 5×5 6×6的6种规格的方形物品,交给顾客的时候需要包装,包装盒长宽高都为6×6,高度为h,为了减少成本,问至少需要多少包装盒才能把全部物品装进去.每一行有6个数,分别表示1×1  2×2 3×3 4×4 5×5 6×6的物品有多少个. 从大到小处理,先放6×6的放一个就需要一个盒子,在放5×5的,每一个也需要一个盒子,但是还可以放11个1×1的物品,放4×4的物品的时

【贪心】POJ1017:Packets

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

poj1017

Packets Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld & %llu Submit Status Practice POJ 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. Th

ERROR 1160 (08S01) : Got an error writing communication packets

? 应用程序端碰到错误提示,MySQLNonTransientConnectionException:Got an error writing communication packets.与packet有关,之前一直都没有碰到过这个问题.数据库error日志也未见半点异常,到底是怎么一回事呢? 1.故障现象故障环境:$ cat /etc/issueCentOS release 5.9 (Final)Kernel \r on an \m [[email protected] ~]$ mysql -

mysql 批量导入 Packets larger than max_allowed_packet are not allowed

解决方法  :http://blog.csdn.net/gtosky4u/article/details/8581281 mysql 批量导入 Packets larger than max_allowed_packet are not allowed,布布扣,bubuko.com

Got timeout reading communication packets解决方法

http://www.th7.cn/db/mysql/201702/225243.shtml [Note] Aborted connection xxxx to db: 问题现象:在tail -f/data/logs/mysql/error.log日志中出现大量的如下信息(web用的是Zabbix,设置连接超时时间为100秒): ' host: 'localhost' (Got timeout reading communication packets)2017-02-05T15:30:19.2

The Everyman&#39;s Guide to How Network Packets Are Routed Across the Web

转自: http://null-byte.wonderhowto.com/how-to/hacker-fundamentals-everymans-guide-network-packets-are-routed-across-web-0134491/ We already covered how your data travels the OSI model, layer by layer, and talks with other machines on your local network