zoukankan      html  css  js  c++  java
  • POJ-1017-Packet(贪心1)

    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 
    #include<stdio.h>
    int cnt2[4]= {0,5,3,1};
    int main()
    {
        int d[10];
        while(scanf("%d%d%d%d%d%d",&d[1],&d[2],&d[3],&d[4],&d[5],&d[6])&&d[1]+d[2]+d[3]+d[4]+d[5]+d[6])
        {
            int n=0;
            n+=d[6]+d[5]+d[4]+(d[3]+3)/4;//一个6*6的箱子最多只能装4个3*3的箱子
            //当d[3]等于5的时候 就要拿另外一个箱子 5加上另外三个空位对4除 则需要两个了
            int d2=d[4]*5+cnt2[d[3]%4]; //d[3]对四取余范围为0到3 一一对应上面找出的规律
            if(d2<d[2])
            {
                n+=(d[2]-d2+8)/9;//当多出的大于了9 10+8/9=2 则另外还需要两个箱子
            }
            int d1=n*36-d[6]*36-d[5]*25-d[4]*16-d[3]*9-d[2]*4;
            if(d1<d[1])
            {
                n+=(d[1]-d1+35)/36;
            }
            printf("%d
    ",n);
        }
        return 0;
    }
  • 相关阅读:
    W13Scan 扫描器挖掘漏洞实践
    golang 单元测试框架实践
    中文分词工具(LAC) 试用笔记
    消息队列Rabbitmq的交换器类型
    docker中使用源码方式搭建SRS流媒体服务
    Ubuntu中使用Nginx+rtmp搭建流媒体直播服务
    Mac下使用Pecl安装PHP的Swoole扩展实践
    Ubuntu中使用Nginx+rtmp模块搭建流媒体视频点播服务
    安卓开发开发规范手册V1.0
    【数据库技术】MySql 45讲整合
  • 原文地址:https://www.cnblogs.com/tianmin123/p/4634985.html
Copyright © 2011-2022 走看看