zoukankan      html  css  js  c++  java
  • POJ 1017 Packets

    Packets
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 51871   Accepted: 17612

    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 

    Source

     
     
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <map>
     4 #include <vector>
     5 #include <functional>
     6 #include <string>
     7 #include <cstring>
     8 #include <queue>
     9 #include <set>
    10 #include <cmath>
    11 #include <cstdio>
    12 using namespace std;
    13 #define IOS ios_base::sync_with_stdio(false)
    14 #define TIE std::cin.tie(0)
    15 #define MIN2(a,b) (a<b?a:b)
    16 #define MIN3(a,b) (a<b?(a<c?a:c):(b<c?b:c))
    17 #define MAX2(a,b) (a>b?a:b)
    18 #define MAX3(a,b,c)  (a>b?(a>c?a:c):(b>c?b:c))
    19 typedef long long LL;
    20 typedef unsigned long long ULL;
    21 const int INF = 0x3f3f3f3f;
    22 const double PI = 4.0*atan(1.0);
    23 
    24 LL ans;
    25 int c1, c2, c3, c4, c5, c6;
    26 int main()
    27 {
    28     while (scanf("%d%d%d%d%d%d", &c1, &c2, &c3, &c4, &c5, &c6) == 6){
    29         if (c1 + c2 + c3 + c4 + c5 + c6 == 0)return 0;
    30         ans = 0;
    31         ans += c6 + c5;// 5*5和6*6都放在一个盒子里
    32         c1 -= c5 * 11;// 一个盒子放了一个5*5之后还可以放11个1*1的
    33         //若有4*4
    34         if (c4>0){
    35             ans += c4;//每个4*4都放入一个盒子中
    36             int num = c4 * 5;//一个盒子放了一个4*4,还可以放5个2*2
    37             //在所有只放了一个4*4的盒子中装入2*2的,如果2*2还有剩余的话,c2不为0
    38             if (c2>num) c2 -= num;
    39             //如果没有剩余了,c2=0,再往剩下的空间放1*1
    40             else c1 -= (num - c2) * 4, c2 = 0;
    41         }
    42         ans += c3 / 4;//每4个3*3放入一个盒子
    43         c3 %= 4;
    44         //可能有一个盒子没有装满,这个盒子可能只放了一个,两个或三个3*3
    45         if (c3 != 0) ans++;
    46         if (c3 == 1){
    47             //盒子只放了一个3*3 剩下的空间装2*2
    48             if (c2 >= 5){
    49                 c2 -= 5;
    50             }
    51             else{
    52                 c1 -= 20 - c2 * 4;
    53                 c2 = 0;
    54             }
    55             c1 -= 7;
    56         }
    57         else if (c3 == 2){
    58             //盒子只放了两个3*3 剩下的空间装2*2
    59             if (c2 >= 3) c2 -= 3;
    60             else{
    61                 c1 -= 12 - c2 * 4;
    62                 c2 = 0;
    63             }
    64             c1 -= 6;
    65         }
    66         else if (c3 == 3){
    67             //盒子放了三个3*3 剩下的空间可以装1个2*2
    68             if (c2>0) c2--;
    69             else c1 -= 4;
    70             c1 -= 5;
    71         }
    72         if (c1<0) c1 = 0;
    73         if (c2>0){
    74             ans += c2 / 9;
    75             if (c2 % 9){
    76                 ans++;
    77                 c1 -= 36 - (c2 % 9) * 4;
    78             }
    79         }
    80         if (c1>0){
    81             ans += c1 / 36;
    82             if (c1 % 36) ans++;
    83         }
    84         printf("%lld
    ", ans);
    85     }
    86     return 0;
    87 }
  • 相关阅读:
    三种方式循环打印1-100的值
    线程中put(None)和主函数中put(None)的区别和用法
    进程、线程这篇博客,让你傻傻的一次就能记清楚
    单生产者进程和单消费者进程
    队列
    初始线程
    常见面试题之*args
    常见面试题之*args 和 **kwargs 的使用
    闭包函数之函数加括号和不加括号的意义
    仓鼠找sugar II
  • 原文地址:https://www.cnblogs.com/cumulonimbus/p/5830667.html
Copyright © 2011-2022 走看看