• POJ1017 Packets


    Packets
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 36663   Accepted: 12207

    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 //代码一:----纯模拟的贪心算法,每次都尽最大的填充
      2 #include<stdio.h>
      3 int main()
      4 {
      5     int i,count;
      6     int a[7];
      7     while(1)
      8     {
      9         for(i=1;i<=6;++i)
     10             scanf("%d",&a[i]);
     11         count=0;
     12         if(a[1]||a[2]||a[3]||a[4]||a[5]||a[6])
     13         {
     14             count=a[6]+a[5]+a[4]+(a[3]+3)/4;     //(a[3]+3)/4可向上取绝对值
     15             a[1]-=11*a[5];
     16             if(a[4])
     17             {
     18                 if(a[2]<5*a[4])
     19                 {
     20                     a[1]-=20*a[4]-a[2]*4;
     21                     a[2]=0;
     22                 }
     23                 else
     24                     a[2]-=5*a[4];
     25             }
     26             if(a[3])
     27             {
     28                 switch (a[3]%4)
     29                 {
     30                     case 0: 
     31                         break;
     32                     case 1:
     33                         {
     34                             if(a[2]<5)
     35                             {
     36                                 a[1]-=(27-a[2]*4);
     37                                 a[2]=0;
     38                             }
     39                             else
     40                             {
     41                                 a[2]-=5;
     42                                 a[1]-=7;
     43                             }
     44                             break;
     45                         }
     46                     case 2:
     47                         {
     48                             if(a[2]<3)
     49                             {
     50                                 a[1]-=(18-4*a[2]);
     51                                 a[2]=0;
     52                             }
     53                             else
     54                             {
     55                                 a[2]-=3;
     56                                 a[1]-=6;
     57                             }
     58                             break;
     59                         }
     60                     default:
     61                         {
     62                             if(a[2])
     63                             {
     64                                 a[2]--;
     65                                 a[1]-=5;
     66                             }
     67                             else
     68                                 a[1]-=9;
     69                             break;
     70                         }        
     71                 }
     72             }
     73             if(a[2]>0)
     74             {
     75                 count+=(a[2]+8)/9;
     76                 a[1]-=36-(a[2]%9)*4;
     77             }
     78             if(a[1]>0)
     79                 count+=(a[1]+35)/36;
     80             printf("%d\n",count);
     81         }
     82         else
     83             break;
     84     }
     85     return 0;
     86 }
     87 
     88 //copy代码:------真短
     89 #include<stdio.h>
     90 int main()
     91 {
     92     int n,a,b,c,d,e,f,x,y;
     93     int u[4]={0,5,3,1};
     94     while(1)
     95     {
     96         scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
     97         if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0)
     98             break;
     99         n=d+e+f+(c+3)/4;
    100         y=5*d+u[c%4];
    101         if(b>y)
    102             n+=(b-y+8)/9;
    103         x=36*n-36*f-25*e-16*d-9*c-4*b;
    104         if(a>x)
    105             n+=(a-x+35)/36;
    106         printf("%d\n",n);
    107     }
    108     return 0;
    109 }
    
    
    功不成,身已退
  • 相关阅读:
    win10安装scrapy
    win10安装 pandas
    scrapy 启动失败,scrapy startproject test 出错 'module' object has no attribute 'OP_NO_TLSv1_1
    Mac环境下安装运行splash
    通过软链接解决目录空间不足的问题
    CentOS 图形界面的关闭与开启
    shell+crontab 实时服务进程监控重启
    Linux下查看yun rpm dpkg 软件是否安装成功的方法
    ubuntu设置root登录ssh
    Ubuntu的中文乱码问题
  • 原文地址:https://www.cnblogs.com/dongsheng/p/2652067.html
Copyright © 2020-2023  润新知