joj1538

 1538: Packets


Result
TIME Limit
MEMORY Limit
Run Times
AC Times
JUDGE
3s
8192K
311
108
Standard
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

#include int a[7]; int main() {     freopen("in.txt","r",stdin);     while(scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6])==6)     {         if(a[1]+a[2]+a[3]+a[4]+a[5]+a[6]==0)   break;         int count=0;         int temp;         count+=a[6]+a[5]+a[4];         int left3=0;         if(a[3]%4==0)         {             count+=a[3]/4;             left3=0;         }         else         {             count+=a[3]/4+1;             left3+=(4-a[3]%4);         }         int left2=a[4]*5;         int left1=a[5]*11;         if(left3==3)         {             left2+=5;             left1+=7;         }         if(left3==2)         {             left2+=3;             left1+=6;         }         if(left3==1)         {             left2+=1;             left1+=5;         }         if(a[2]>left2)         {             a[2]-=left2;             if(a[2]%9==0)             count+=a[2]/9;             else             {                 count+=a[2]/9+1;                 left1+=4*(9-a[2]%9);             }         }         else         {            left2-=a[2];            left1+=left2*4;         }         if(a[1]>left1)         {             a[1]-=left1;             if(a[1]%36==0)             count+=a[1]/36;             else             count+=a[1]/36+1;         }         printf("%d",count);     }     return 0; } 이 문제에 대해 나는 매우 깊은 감명을 받았다. 이 문제는 처음부터 내가 잘못 생각했다. 전체 6*6의 칸을 구분할 수 있다고 생각했는데 한 시간 동안 디버깅을 하지 않았다. 마지막에 하나의 사고방식을 바꿔서 디버깅을 했다. 다음은 나의 첫 번째 오류 코드이다.3*3 1개와 2*2 5개의 제목 아래 코드는 오류입니다.
/*#include int packet[7]; bool exam() {     for(int i=1;i<=6;i++)     {         if(packet[i]!=0)         return false;     }     return true; } void cal(int u,int v) {     for(int i=6;i>0;i--)     {         if(packet[i]!=0)         {             if(u>=i&&v>=i)             {                 packet[i]--;                 if(u>v)                 {                     if(u-i>v)                         cal(u-i,v);                     else                         cal(v,u-i);                     if(i>v-i)                         cal(i,v-i);                     else                         cal(v-i,i);                     v=v-i;                     u=u-i;                 }                 else                 {                     if(i>u-i)                         cal(i,u-i);                     else                         cal(u-i,i);                     if(v-i>u)                         cal(v-i,u);                     else                         cal(u,v-i);                     v=v-i;                     u=u-i;                 }             }         }     } } int main() {     freopen("in.txt","r",stdin);    //freopen("out.txt","w",stdout);     bool first=true;     while(1)     {         bool temp=false;         for(int i=1;i<=6;i++)         {             scanf("%d",&packet[i]);             if(packet[i]!=0)             temp=true;         }         if(!temp)break;         if(!first)         printf("");         first=false;         int num=0;         while(!exam())         {             cal(6,6);             num++;         }         printf("%d",num);     }     return 0; } */

좋은 웹페이지 즐겨찾기