poj 1017 Packets

xiaoxiao2021-02-27  373

Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 54722 Accepted: 18607 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

Central Europe 1996

#include<stdio.h> #include<algorithm> using namespace std; int main() { int a[10]; //freopen("E:\\input.txt","r",stdin); //freopen("E:\\output.txt","w",stdout); while(scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6])!=EOF) { if(a[1]+a[2]+a[3]+a[4]+a[5]+a[6]==0) break; int ans=a[6]+a[5]+a[4]; //5+1; int temp=a[5]*11; if(temp>=a[1]) a[1]=0; else a[1]=a[1]-temp; //4+2+1; temp=a[4]*5; if(temp>=a[2]){ a[4]=(temp-a[2])*4; //此时a[4]存的是a[1]的理想个数 a[2]=0; if(a[4]>=a[1]) a[1]=0; else a[1]=a[1]-a[4]; } else a[2]=a[2]-temp; //3+3+2+1; ans+=a[3]/4; temp=a[3]%4; int temp1=0,temp2=0; if(temp==1){ temp1=7; temp2=5; ans++; } else if(temp==2){ temp1=6; temp2=3; ans++; } else if(temp==3){ temp2=1; temp1=5; ans++; } else{ temp1=0; temp2=0; } a[2]=a[2]-temp2; a[1]=a[1]-temp1; if(a[2]<0&&a[1]>0) a[1]=a[1]+a[2]*4; if(a[2]>0){ ans+=a[2]/9; if(a[2]%9){ a[2]=36-a[2]%9*4; a[1]=a[1]-a[2]; ans++; } } if(a[1]>0){ ans+=a[1]/36; ans+=(a[1]6==0?0:1); } printf("%d\n",ans); } return 0; } #include<cstdio> using namespace std; int main(){ int a[10]; int space[4] = {0 ,5,3,1}; int n = 0; int y ; int x; while(scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6])!=EOF){ if(a[1]==0&&a[2]==0&&a[3]==0&&a[4]==0&&a[5]==0&&a[6]==0) break; n = a[6] + a[5] +a[4] +(a[3]+3)/4; y = 5*a[4] + space[a[3]%4]; if(a[2] >y){ n+=(a[2]-y+8)/9; } x = 36*n -36*a[6] - 25*a[5] - 16*a[4] * 9*a[3] - 4*a[2]; if(a[1]>x){ n+=(a[1]-x+35)/36; } printf("%d\n" , n); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-969.html

最新回复(0)