POJ1017 Packets---贪心

时间:2023-02-02 21:35:20

题目链接:

https://vjudge.net/problem/POJ-1017

题目大意:

公司共有底面面积为1*1、2*2、3*3、4*4、5*5、6*6,高度同为H的六种产品,现在需要用最少的箱子打包,箱子的底面面积为6*6,高度为H。

思路:

简单的暴力贪心算法,对不同的产品有不同的策略,按照从大到小的顺序打包产品,策略如下:

 6*6:1个产品放在1个箱子里

5*5:1个产品要占用1个箱子,用1*1的箱子可以填充(11个填满1箱)

 4*4:1个产品要占用1个箱子,剩余空间用2*2和1*1的箱子填充(先填充2*2,再填充1*1)

3*3:4个产品可以填满1个箱子,假如有不满1个箱子的,分情况用1*1和2*2的产品填满

 2*2:9个产品可以填满1个箱子,假如有不满1个箱子的,用1*1的产品填充

   1*1:36个产品可填满一个箱子

 #include<iostream>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll; int main()
{
int a, b, c, d, e, f;
while(cin >> a >> b >> c >> d >> e >>f && (a + b + c + d + e + f))
{
int ans = d + e + f + (c + ) / ;
int aa = a, bb = b, cc = c;
aa -= e * ;
if(aa < )aa = ;
bb -= d * ;
if(bb < )
{
bb = ;
aa -= (d * - b * );
if(aa < )aa = ;
}
if(c % == )
{
if(bb >= )
{
bb--;
aa -= ;
}
else
{
aa -= ;
}
}
else if(c % == )
{
if(bb >= )bb -= ,aa -= ;
else if(bb == )bb = ,aa -= ;
else if(bb)bb = , aa -= ;
else a -= ;
}
else if( c % == )
{
if(bb >= ) bb -= , aa -= ;
else
{
bb = ;
if(bb == )aa -= ;
else if(bb == )aa -= ;
else if(bb == )aa -= ;
else if(bb == )aa -= ;
else aa -= ;
}
}
else;
if(aa < )aa = ;
if(bb < )bb = ;
ans = ans + (bb * + aa + ) / ;
cout<<ans<<endl;
}
}

POJ1017 Packets---贪心的更多相关文章

  1. poj-1017 Packets (贪心)

    http://poj.org/problem?id=1017 工厂生产高度都为h,长和宽分别是1×1 2×2 3×3 4×4 5×5 6×6的6种规格的方形物品,交给顾客的时候需要包装,包装盒长宽高都 ...

  2. UVA 311 Packets 贪心&plus;模拟

    题意:有6种箱子,1x1 2x2 3x3 4x4 5x5 6x6,已知每种箱子的数量,要用6x6的箱子把全部箱子都装进去,问需要几个. 一开始以为能箱子套箱子,原来不是... 装箱规则:可以把箱子都看 ...

  3. poi 1017 Packets 贪心&plus;模拟

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 48349   Accepted: 16392 Descrip ...

  4. POJ1017 packets

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 48911   Accepted: 16570 Descrip ...

  5. A - Packets 贪心

    A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, ...

  6. Poj 1017 Packets&lpar;贪心策略&rpar;

    一.题目大意: 一个工厂生产的产品用正方形的包裹打包,包裹有相同的高度h和1*1, 2*2, 3*3, 4*4, 5*5, 6*6的尺寸.这些产品经常以产品同样的高度h和6*6的尺寸包袱包装起来运送给 ...

  7. POJ 1O17 Packets &lbrack;贪心&rsqb;

    Packets Description A factory produces products packed in square packets of the same height h and of ...

  8. poj 1017 Packets 贪心

    题意:所有货物的高度一样,且其底面积只有六种,分别为1*1 2*2 3*3 4*4 5*5 6*6的,货物的个数依次为p1,p2,p3,p4,p5,p6, 包裹的高度与货物一样,且底面积就为6*6,然 ...

  9. 《挑战程序设计竞赛》2&period;2 贪心法-其它 POJ3617 3069 3253 2393 1017 3040 1862 3262

    POJ3617 Best Cow Line 题意 给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下列任意操作: 从S的头部(或尾部)删除一个字符,加到T的尾部 ...

  10. poj 1017 Packets 裸贪心

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43189   Accepted: 14550 Descrip ...

随机推荐

  1. hibernate入门案例

    最近准备学ssh,今天学了一下hibernate,用的是hibernate4,现在已经出5了:配置文件很容易写错,写配置文件的时候尽量复制. 需要的jar包如下:(jar包我是直接放在项目工程里面了, ...

  2. Hierarchyid 常用操作

        ---------内置函数------------ select hierarchyid::GetRoot()--0x select hierarchyid::Parse('/1/1/') - ...

  3. js接受url参数

    1.正则表达式 function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=( ...

  4. 多个github帐号的SSH key切换

    写在前面的话 github账号,工作有一个,自己有一个.但是默认下使用ssh key在git push时只有默认账号能免输入账号和密码. 如果想让另一个账号在代码push时免账号和密码,请看这篇文章h ...

  5. spring配置详解

    1.前言 公司老项目的后台,均是基于spring框架搭建,其中还用到了log4j.jar等开源架包.在新项目中,则是spring和hibernate框架均有使用,利用了hibernate框架,来实现持 ...

  6. FPGA 设计总结(1)

    1. set_input_delay和set_output_delay的选项-max和-min的理解 首先 input/output其实是模拟数据在端口外的延时,是一个外部约束条件,目的是为了约束FP ...

  7. 开机出现 grub rescue&gt&semi; 终端模式修复方法

    1.  先使用ls命令,找到Ubuntu的安装在哪个分区:     grub rescue>ls     会罗列所有的磁盘分区信息,比方说:     (hd0),(hd0,msdos3),(hd ...

  8. Linux&plus;树莓派3开发总结——树莓派远程文件共享winows

    http://blog.csdn.net/xqf1528399071/article/details/52192134 ———————————————————————————————————————— ...

  9. MySQL-五种日志&lpar;查询日志、慢查询日志、更新日志、二进制日志、错误日志&rpar;、备份及主从复制配置

    开启查询日志: 配置文件my.cnf: log=/usr/local/mysql/var/log.log 开启慢查询: 配置文件my.cnf: log-slow-queries=/usr/local/ ...

  10. 代码收藏系列--javascript--移动端技巧

    JS判断是否是手机端访问: var is_mobi = navigator.userAgent.toLowerCase().match(/(ipod|iphone|android|coolpad|mm ...