poj 1017 Packets
2017-11-23 20:23
323 查看
Packets
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 57248 Accepted: 19424
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
思维,细节
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n1, n2, n3, n4, n5, n6, num, sum; int t[]={0,5,3,1};///3*3->2*2 int u[]={0,7,6,5};///3*3->1*1 int main() { //freopen( "in.txt", "r", stdin ); while( scanf( "%d%d%d%d%d%d", &n1, &n2, &n3, &n4, &n5, &n6 ) != EOF ){ if( n1 + n2 + n3 + n4 + n5 + n6 == 0 ) break; sum = n6 + n5 + n4; int nm1, nm2; nm1 = n3 / 4; nm2 = n3 % 4; if( nm2 == 0 ){/// sum += nm1; } else{ sum += nm1 + 1; } num = n4 * 5 + t[nm2]; if( n2 >= num ){ n2 -= num; num = 0; if( n2 % 9 ){ sum += n2 / 9 + 1; num = 9 - n2 % 9;/// } else sum += n2 / 9; } else{ num -= n2; n2 = 0; }//cout<<sum<<" "<<num<<"_"; num = num * 4 + n5 * 11 + u[nm2];/// if( n1 >= num ){ n1 -= num; if( n1 % 36 != 0 ) sum += n1 / 36 + 1; else sum += n1 / 36; } printf( "%d\n", sum ); } return 0; }
相关文章推荐
- POJ 1017Packets(贪心)
- POJ 1017 Packets (典型的贪心算法)
- POJ 1017:Packets
- poj 1017 packets (贪心)
- poj-1017-packets
- POJ 1017:Packets
- poj 1017 Packets ( 贪心 )
- Packets - POJ 1017 水题
- POJ 1017 Packets(构造模拟)
- POJ 1017 Packets
- POJ1017_Packets_贪心
- POJ-1017 Packets
- POJ 1017 Packets
- POJ 1017:Packets
- poj 1017 Packets
- poj 1017 Packets 贪心
- POJ 1017 Packets
- POJ 1017: Packets
- POJ 1017 Packets-装格子 (简单贪心)
- poj 1017 Packets