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;
    }
  • 相关阅读:
    Unity物理系统随记
    Unity相机跟随小结
    unity制作赛车游戏
    动态编程
    C#-特性,反射,动态编程
    BASE64加解密
    idea快捷键
    git安装和git命令:全局设置用户名邮箱配置
    基于Node.js+MySQL开发的开源微信小程序商城(微信小程序)部署环境
    微信小程序开发入门(一),Nodejs搭建本地服务器
  • 原文地址:https://www.cnblogs.com/tianmin123/p/4634985.html
Copyright © 2011-2022 走看看