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

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

Source

很不错的一道题目,贪心的话就不讲了,先放大的,再放小的,刚开始我是分过程一个一个模拟的,也就是在当前情况下再分子情况讨论,,有些繁琐,当然更容易错,看了下大牛的博客,,zzz,瞬间膜拜,上代码
<span style="font-size:32px;">#include <iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
int a[8],u[4]={0,5,3,1};
int main()
{
while(~scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6]))
{
if(!a[1]&&!a[2]&&!a[3]&&!a[4]&&!a[5]&&!a[6])
return 0;
int cnt=a[6]+a[5]+a[4]+(a[3]+3)/4;/*先装好能“独当一面的”大快 递物品,初步确定至少要的箱子数目/
int t2=a[4]*5+u[a[3]%4];/*确定好再上一行代码的情况下,能额外放 入2*2物品的数目*/
if(a[2]>t2)
cnt+=(a[2]-t2+8)/9;/*需要为a[2]单独再开箱子*/
int t1=cnt*36-a[6]*36-a[5]*25-a[4]*16-a[3]*9-a[2]*4;/*补a[1]*/
if(a[1]>t1)
cnt+=(a[1]-t1+35)/36;
printf("%d\n",cnt);
}
return 0;
}
</span>

最后附上本人起初写的wrong
answe代码,一步一步暴力。。

再度膜拜大牛
#include <iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
int a[8];
int main()
{
while(~scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6]))
{
if(a[1]+a[2]+a[3]+a[4]+a[5]+a[6]==0)
return 0;
int cnt=a[6]+a[5]+a[4];
a[1]-=a[5]*11;
a[2]-=a[4]*5;
int t3=(a[3]-1+4)/4;
cnt+=t3;
if(a[3]%4!=0)
{
int yu=4-a[3]%4;
if(yu==3)
{
if(a[2]>0)
if(a[2]>=5)
{
a[2]-=5;
a[1]-=7;
}
else
{
a[1]-=27-a[2]*4;
a[2]=0;
}
}
else if(yu==2)
{
if(a[2]>0)
if(a[2]>=3)
{
a[2]-=3;
a[1]-=6;
}
else
{
a[1]-=12-a[2]*4;
a[2]=0;
}
}
else if(yu==1)
{
if(a[2]>=1)
{
a[2]-=1;
a[1]-=3;
}
else
a[1]-=9;
}
}
if(a[2]>0)
{
cnt+=(a[2]-1+9)/9;
a[2]%=9;
a[1]-=36-a[2]*4;
}
if(a[1]>0)
{
cnt+=(a[1]-1+36)/36;
}
printf("%d\n",cnt);
}
return 0;
}





poi 1017 Packets 贪心+模拟的更多相关文章

  1. UVA 311 Packets 贪心+模拟

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

  2. Poj 1017 Packets(贪心策略)

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

  3. poj 1017 Packets 贪心

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

  4. POJ:1017-Packets(贪心+模拟,神烦)

    传送门:http://poj.org/problem?id=1017 Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...

  5. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  6. 贪心+模拟 ZOJ 3829 Known Notation

    题目传送门 /* 题意:一串字符串,问要最少操作数使得成为合法的后缀表达式 贪心+模拟:数字个数 >= *个数+1 所以若数字少了先补上在前面,然后把不合法的*和最后的数字交换,记录次数 岛娘的 ...

  7. CodeForces ---596B--Wilbur and Array(贪心模拟)

    Wilbur and Array Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Su ...

  8. poj 1017 Packets 裸贪心

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

  9. POJ 1017 Packets【贪心】

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

随机推荐

  1. luffy前台配置

    目录 axios前后台交互 cokies操作 element-ui页面组件框架 bootstrap页面组件框架 前端主页 图片准备 页头组件:components/Header.vue 轮播图组件:c ...

  2. 并不对劲的复健训练-bzoj5253:loj2479:p4384:[2018多省联考]制胡窜

    题目大意 给出一个字符串\(S\),长度为\(n\)(\(n\leq 10^5\)),\(S[l:r]\)表示\(S_l,S_{l+1}...,S_r\)这个子串.有\(m\)(\(m\leq 3\t ...

  3. Ubuntu系统开机后不能正常使用——问题解决记录

    1.开机后桌面内容没了,搜狗输入法不能使用了,终端不能打开了 问题原因:上次关机前为了解决解压文件中文乱码问题,在/etc/profile末尾加了如下两行:(但事实上如下两行根本不能解决中文乱码问题) ...

  4. 搭建自己的框架WedeNet(二)

    WedeNet2018.Infrastructure-基础设施层:结构如下: Tools结构如下: 考虑到系统可能会有多个数据上下文(暂时以两个为例),所以根据需要定义两个T4模板用来生成对应的ent ...

  5. arcgis之隐藏设置放大缩小按钮

    arcgis之隐藏设置放大缩小按钮 隐藏按钮: view.ui._removeComponents(['zoom']) 设置按钮: let zoom = new Zoom({ view: this.v ...

  6. Vue访问权限

    设置权限 <script> export default { created(){ if(this.$store.state.userStore.role !== 'manager'){ ...

  7. javascript学习方法指南

    Javascript看似无限的可能性使得基于HTML和CSS的公共网站成为过去.然而,尽管JavaScript为用户提供了出色的动态体验,但它也为开发人员创建了一个雷区.因此,Javascript搜索 ...

  8. 6 java 笔记

    1 java的类通过构造器来创建该类的对象 2 java提供extends关键字来实现子类继承父类 3 初始化块总是在构造器调用之前被执行 4 可以吧java中的类当成一种自定义的类型 5 类定义的变 ...

  9. Java web 项目 web.xml 配置文件加载过程

    转载自:http://blog.csdn.net/luoliehe/article/details/46884757#comments WEB加载web.xml初始化过程: 在启动Web项目时,容器( ...

  10. C++ void*解惑

    最近遇到void *的问题无法解决,发现再也无法逃避了(以前都是采取悄悄绕过原则),于是我决定直面它. 在哪遇到了? 线程创建函数pthread_create()的最后一个参数void *arg,嗯? ...