Packets
Packets |
A factory produces products packed in square packets of the same height h and of the sizes , , , , , . These products are always delivered to customers in the square parcels of the same height h as the products have and of the size . 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 to the biggest size . 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
题目不难。。按自己的想法做就行。。。
目测一下大概wa了8次才ac
主要原因是当b<0时用a填补是必须将b置为0!!!!!!
否则会重复计算!
ac代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <vector>
#include <stack>
#include <map>
#include <queue>
#include <iostream>
#include <stdlib.h>
#define rep(i,s,e) for(int i = (s);i<=(e);++i)
using namespace std;
//311
int num[] = {5,3,1};
int main()
{
int a,b,c,d,e,f;
//freopen("in.txt","r",stdin);
//int first = 0;
while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)==6)
{
if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0)
break;
//if(first)
//printf("\n");
//first = 1;
int sum = 0;
sum += f;//6
sum += e;//5
sum += d;//4
a -= 11*e;
b -= 5*d;
if(b<=0)
{
a += 4*b;
b = 0;
}
sum += c/4;
int temp = c%4;
if(temp)
{
sum++;
b -= num[temp-1];
a = a-(36 - 4*num[temp-1]-temp*9);
if(b<=0)
{
a += 4*b;
b = 0;
}
}
if(b>0)
{
sum += b/9;
int temp2 = b%9;
if(temp2)
{
sum++;
a -= 4*(9-temp2);
}
}
if(a>0)
{
sum += a/36;
if(a%36)
sum++;
}
printf("%d\n",sum);
}
return 0;
}