zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    ios app 开发中ipa重新签名步骤介绍-备
    推荐IOS开发3个工具:Homebrew、TestFight、Crashlytics-b
    iOS开发工具——统计Crash的工具Crashlytics-备用
    摘要算法
    Xcode中将图片放入Images.xcassets和直接拖入的区别
    PHP面向对象的基本写法(区别于java)
    PHP 解决时差8小时的问题
    Java-Hirbernate小结大纲
    PHP替换数据库的换行符
    Java-strurs总结
  • 原文地址:https://www.cnblogs.com/haoabcd2010/p/6950631.html
Copyright © 2011-2022 走看看