zoukankan      html  css  js  c++  java
  • poj-1017 Packets (贪心)

    http://poj.org/problem?id=1017

    工厂生产高度都为h,长和宽分别是1×1 2×2 3×3 4×4 5×5 6×6的6种规格的方形物品,交给顾客的时候需要包装,包装盒长宽高都为6×6,高度为h,为了减少成本,问至少需要多少包装盒才能把全部物品装进去。每一行有6个数,分别表示1×1  2×2 3×3 4×4 5×5 6×6的物品有多少个。

     从大到小处理,先放6×6的放一个就需要一个盒子,在放5×5的,每一个也需要一个盒子,但是还可以放11个1×1的物品,放4×4的物品的时候,还可以放2×2的和1×1的,最复杂的事放3×3的,有多种情况需要考虑,要细心,我也是用了别人的测试数据才改出来的。

      1 #include <iostream>
      2 #include <cstdio>
      3 #include <cmath>
      4 #include <vector>
      5 #include <cstring>
      6 #include <string>
      7 #include <algorithm>
      8 #include <string>
      9 #include <set>
     10 #include <functional>
     11 #include <numeric>
     12 #include <sstream>
     13 #include <stack>
     14 #include <map>
     15 #include <queue>
     16 
     17 #define CL(arr, val)    memset(arr, val, sizeof(arr))
     18 
     19 #define ll long long
     20 #define inf 0x7f7f7f7f
     21 #define lc l,m,rt<<1
     22 #define rc m + 1,r,rt<<1|1
     23 #define pi acos(-1.0)
     24 
     25 #define L(x)    (x) << 1
     26 #define R(x)    (x) << 1 | 1
     27 #define MID(l, r)   (l + r) >> 1
     28 #define Min(x, y)   (x) < (y) ? (x) : (y)
     29 #define Max(x, y)   (x) < (y) ? (y) : (x)
     30 #define E(x)        (1 << (x))
     31 #define iabs(x)     (x) < 0 ? -(x) : (x)
     32 #define OUT(x)  printf("%I64d
    ", x)
     33 #define lowbit(x)   (x)&(-x)
     34 #define Read()  freopen("a.txt", "r", stdin)
     35 #define Write() freopen("b.txt", "w", stdout);
     36 #define maxn 1000000000
     37 #define N 10010
     38 using namespace std;
     39 
     40 int main()
     41 {
     42   //Read();
     43    //Write()
     44    int a,b,c,d,e,f,s;
     45    while(~scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f))
     46    {
     47        if(a+b+c+d+e+f==0) break;
     48        s=f;   //6*6的
     49        if(e>0)  //5*5的
     50        {
     51            s+=e;
     52            a-=11*e;
     53        }
     54       //printf("%d %d
    ",s,a);
     55        if(d>0)  //4×4的
     56        {
     57            s+=d;
     58            int b1=5*d; //可以放 b1个2×2的 
     59            b-=b1;   
     60            if(b<0)  //2×2不够,就放1×1的
     61            {
     62                a-=-4*b;
     63            }
     64        }
     65     //printf("%d %d %d
    ",s,a,b);
     66        if(c>0)
     67        {
     68            s+=c/4;
     69            int c1=c%4;
     70            if(c1)
     71            {   //分情况讨论,c1=1,=2,=3 
     72                s++;
     73                if(b>0)
     74                {
     75                    int b1=b;
     76                    if(c1==1)  b-=5;
     77                    else if(c1==2) b-=3;
     78                    else if(c1==3) b-=1;
     79                    if(b>=0) a-=36-c1*9-(b1-b)*4; //还可以放1×1的  
     80                    else a-=36-c1*9-b1*4;
     81                }
     82                else a-=36-c1*9;
     83            }
     84        }
     85     //  printf("%d %d %d
    ",s,a,b);
     86        if(b>0)   //2×2 的
     87        {
     88            s+=b/9;
     89            int b1=b%9;
     90            if(b1)
     91            {
     92                s++;
     93                if(a>0) a-=36-b1*4;
     94            }
     95        }
     96        if(a>0) //1×1 的
     97        {
     98            s+=a/36;
     99            if(a%36>0) s++;
    100        }
    101        printf("%d
    ",s);
    102    }
    103    return 0;
    104 }
  • 相关阅读:
    MySQL中mysqldump导出数据的使用
    MySQL中show语法使用总结
    Nginx配置项优
    Elasticsearch5.2.2安装
    SSH实现双向认证
    MySQL5.6主从复制搭建基于日志(binlog)
    清除Pycharm设置的方法
    Python3编程技巧
    django组件-中间件
    Python打杂之路
  • 原文地址:https://www.cnblogs.com/nowandforever/p/4417252.html
Copyright © 2011-2022 走看看