• Packets


    Packets

    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

     

     

    //告诉你1*1,2*2,3*3......6*6 方块的数量,问最少需要多少个容量为6*6的容器才能装下

     

    //显然贪心可做,但是这题数据还是不弱的,wa了好几发。。要细心

     1 #include <stdio.h>
     2 using namespace std;
     3 
     4 int box[7];
     5 int main()
     6 {
     7     while (1)
     8     {
     9         int all=0;
    10         for (int i=1;i<=6;i++)
    11         {
    12             scanf("%d",&box[i]);
    13             all+=box[i];
    14         }
    15         if (all==0) break;
    16 
    17         int ans = box[4]+box[5]+box[6];
    18         int x2 = 5*box[4];
    19         int x1 = 11*box[5];
    20         if (x2>box[2])
    21         {
    22             x1+=(x2-box[2])*4;
    23             x2=box[2];
    24         }
    25 
    26         int t=box[3]%4;
    27         if (t) ans++;
    28         ans += box[3]/4;
    29         if (t==1) x2+=5,x1+=7;
    30         if (t==2) x2+=3,x1+=6;
    31         if (t==3) x2+=1,x1+=5;
    32         if (x2>box[2])
    33         {
    34             x1+=(x2-box[2])*4;
    35             x2=box[2];
    36         }
    37 
    38         if (x2<box[2])
    39         {
    40             int re = box[2]-x2;
    41             int t =re%9;
    42             if (t)
    43             {
    44                 x1+=(9-t)*4;
    45                 ans++;
    46             }
    47             ans +=re/9;
    48         }
    49 
    50         if (x1<box[1])
    51         {
    52             int re = box[1]-x1;
    53             int t = re%36;
    54             ans += re/36;
    55             if (t) ans++;
    56         }
    57         printf("%d
    ",ans);
    58     }
    59     return 0;
    60 }
    View Code
  • 相关阅读:
    Ceph
    linux五天光速入门
    shell编程
    Docker&K8S&持续集成与容器管理--系列教程
    openstack系列
    爬虫快速入门
    python奇闻杂技
    机器学习
    数据分析
    量化分析
  • 原文地址:https://www.cnblogs.com/haoabcd2010/p/6950631.html
Copyright © 2020-2023  润新知