若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

3155: 贪心之Packets

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,243

题目描述

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.

输入

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.

输出

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.

样例输入

0 0 4 0 0 1
7 5 1 0 0 0
0 0 0 0 0 0

样例输出

2
1

参考代码

#include<stdio.h>
int main() 
{
    int num,a,b,c,d,e,f,x,y;
    int u[4]={0,5,3,1};
    while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)) 
    {
        if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0)
                    break;
        num=d+e+f+(c+3)/4;
        y=5*d+u[c%4];
        if(b>y)
                    num=num+(b-y+8)/9;
        x=36*num-36*f-25*e-16*d-9*c-4*b;
        if(a>x)
                    num=num+(a-x+35)/36;
        printf("%dn",num);
    }
    return 0;
}

解析

暂无

hustoj

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

原站点 Dreams孤独患者 Skip
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist