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 Spring boot使用spring反射

    spring 反射 当你配置各种各样的bean时,是以配置文件的形式配置的,你需要用到哪些bean就配哪些,spring容器就会根据你的需求去动态加载,你的程序就能健壮地运行. 1.可以通过类名去实例 ...

  2. 让Dreamweaver支持cshtml (MVC Razor环境)

    介绍:让Dreamweaver支持cshtml 正文: 如题,刚才搜了很久,都搜不到答案,幸好得到“包大人”(同事)的帮助,才得以解决. DW支持很多文件类型的代码提示,可是类型太多,不可能全部都有, ...

  3. Pc移植到Mac的技术细节

    1.样式不对: 2.布局不对: 3.Mac的菜单替换PC的菜单: Mac的菜单替换PC的菜单: 1)左上角图标没有手动添加且不需要添加的情况下出现,而且点击是Help菜单内容: 2)把HelpBtn和 ...

  4. 【APUE】Chapter4 File and Directories

    4.1 Introduction unix的文件.目录都被当成文件来看待(vi也可以编辑目录):我猜这样把一起内容都当成文件的原因是便于统一管理权限这类的内容 4.2 stat, fstat, fst ...

  5. 谷歌js编码规范解析

    http://alloyteam.github.io/JX/doc/specification/google-javascript.xm 阅读了谷歌js编码规范,我发现了很多,js的里面很多要注意的问 ...

  6. flask中static_folder与static_url_path的区别与联系

    # -*- coding:utf-8 -*- from flask import Flask, url_for app1 = Flask(__name__, static_folder='mystat ...

  7. python 正则表达式 (重点) re模块

    京东的注册页面,打开页面我们就看到这些要求输入个人信息的提示.假如我们随意的在手机号码这一栏输入一个11111111111,它会提示我们格式有误.这个功能是怎么实现的呢?假如现在你用python写一段 ...

  8. zabbix从入门到精通

    第1章 zabbix监控 1.1 为什么要监控 在需要的时刻,提前提醒我们服务器出问题了 当出问题之后,可以找到问题的根源   网站/服务器 的可用性 1.1.1 网站可用性 在软件系统的高可靠性(也 ...

  9. NO5——素数筛选

    #include <stdio.h> int main() { ]={}; ;i<=;i++) a[i]=; ;i<=;i++) if(a[i]) ;j+=i) a[j]=; ...

  10. [转]juery-zTree的基本用法

    [简介] zTree 是利用 jQuery 的核心代码,实现一套能完成大部分常用功能的 Tree 插件 兼容 IE.FireFox.Chrome 等浏览器 在一个页面内可同时生成多个 Tree 实例 ...