Packets
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 59725   Accepted: 20273

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

http://poj.org/problem?id=1017

题意:给你一些体积大小为1x1,2x2,3x3,4x4,5x5,6x6的方块,需要你装6x6的盒子里面,求最少需要的盒子

从6x6的方块开始装,然后一个5x5的方块与11个1x1的方块装一个箱子,4x4的方块与5个2x2的方块或者x个1x1的方块装一个箱子

依次贪心,最后可得公式所需最少的盒子为 ans=f+e+d+(c+3)/4+cnt2+cnt1个;

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int a,b,c,d,e,f; int main()
{
while(cin>>a>>b>>c>>d>>e>>f){
if(!a&&!b&&!c&&!d&&!e&&!f) break;
int ans=f+e+d+(c+)/;
int cnt2=;
cnt2+=*d;
if(c%==){
cnt2+=;
}else if(c%==){
cnt2+=;
}else if(c%==){
cnt2+=;
}
if(cnt2<b){
ans+=(((b-cnt2)+)/);
}
int cnt1;
cnt1=*ans-*f-*e-*d-*c-*b;
if(cnt1<a){
ans+=((a-cnt1)+)/;
}
printf("%d\n",ans);
}
return ;
}

POJ - 1017 贪心训练的更多相关文章

  1. POJ 1017 Packets【贪心】

    POJ 1017 题意: 一个工厂制造的产品形状都是长方体,它们的高度都是h,长和宽都相等,一共有六个型号,他们的长宽分别为 1*1, 2*2, 3*3, 4*4, 5*5, 6*6.  这些产品通常 ...

  2. poj 1017 Packets 裸贪心

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

  3. Poj 1017 Packets(贪心策略)

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

  4. poj 1017 装箱子(模拟+贪心)

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

  5. poj 1017 Packets 贪心

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

  6. poj 1017 装箱子问题 贪心算法

    题意:有1*1到6*6的的东西,需要用6*6的箱子将它们装起来.问:至少需要多少个6*6箱子 思路: 一个瓶子怎么装东西最多?先装石头,在装沙子,然后装水. 同样放在本题就是先装6*6然后5*5... ...

  7. POJ 1017 Packet

    http://poj.org/problem?id=1017 有1*1 2*2...6*6的物品 要装在 6*6的parcel中 问最少用多少个parcel 一直没有找到贪心的策略 问题应该出现在 总 ...

  8. POJ 1017

    http://poj.org/problem?id=1017 题意就是有6种规格的物品,给你一些不同规格的物品,要求你装在盒子里,盒子是固定尺寸的也就是6*6,而物品有1*1,2*2,3*3,4*4, ...

  9. Poj 1017 / OpenJudge 1017 Packets/装箱问题

    1.链接地址: http://poj.org/problem?id=1017 http://bailian.openjudge.cn/practice/1017 2.题目: 总时间限制: 1000ms ...

随机推荐

  1. java容器操作一

    List l = new ArrayList(); l.add(1); l.add("ne"); // 获取 System.out.println(l.get(0)); // 判断 ...

  2. 年薪20万Python工程师进阶(7):Python资源大全,让你相见恨晚的Python库

    我是 环境管理 管理 Python 版本和环境的工具 pyenv – 简单的 Python 版本管理工具. Vex – 可以在虚拟环境中执行命令. virtualenv – 创建独立 Python 环 ...

  3. HI2115软件开发板V150版本AT+NSOST指令

    1. 在HI2115里面,由于内存空间比较大,所以支持UDP发送指令AT+NSOST的分包 ret = sendto(socket, seq_num, data_string, length, msg ...

  4. Vuex实践

    本文来自网易云社区 作者:刘凌阳 前言 2017年对于Vue注定是不平凡的一年.凭借着自身简介.轻量.快速等特点,Vue俨然成为最火的前端MVVM开发框架.随着Vue2.0的release,越来越多的 ...

  5. ubuntu apt-get 使用代理设置,坑爹。。

    网上流传的export http_proxy=http://yourproxyaddress:proxyport是行不通的,虽然改了之后wget一类的可以用.当然去改.bashrc也不会有效果. 真正 ...

  6. Qt BarChart实践

    按照帮助文档编写 运行截图 上代码 #include "widget.h" #include "ui_widget.h" Widget::Widget(QWid ...

  7. 第二十三篇 logging模块(******)

    日志非常重要,而且非常常用,可以通过logging模块实现. 热身运动 import logging logging.debug("debug message") logging. ...

  8. gcc6.3编译c++11的程序链接opencv时字符型函数未定义

    在Windows下编写图像处理程序,由于要使用regex,升级了mingw,编译c++11代码.之前代码中使用了opencv2.4.10,一直运行良好,升级编译器以后发现了错误:undefined r ...

  9. redis-Windows下安装与操作

    Redis windows下安装 1.安装 (1)windows把redisbin_x32安装包放在电脑任意的盘里 (2)通过cmd找到对应目录:  D\redisbin_x32 (3)开始安装 D\ ...

  10. tcp四次撒手

    转自:http://www.cnblogs.com/cy568searchx/p/3711670.html 由于TCP连接是全双工的,因此每个方向都必须单独进行关闭.这个原则是当一方完成它的数据发送任 ...