Packing Problem

Packing Problem

description:

A factory produces cuboid productions with hight \emph{h}. For each production, its length and wideness are the same. There are six types of productions whose length and wideness are 1*1, 2*2, 3*3, 4*4, 5*5, and 6*6. These productions are usually delivered to customers in the form of 6*6*h packages. As the delivery fee is expensive, this problem asks students to determine how workers should pack the productions yielding the minimal delivery fee.

source:

right:venushjx

--------------------------------------------------------------------------------------------------

import java.io.*;import java.util.*;public class Main{ public static void main(String[]args)throws Exception{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int N,a,b,c,d,e,f,x,y; int u[]={0,5,3,1}; while(true){ StringTokenizer st=new StringTokenizer(br.readLine()); a=Integer.parseInt(st.nextToken()); b=Integer.parseInt(st.nextToken()); c=Integer.parseInt(st.nextToken()); d=Integer.parseInt(st.nextToken()); e=Integer.parseInt(st.nextToken()); f=Integer.parseInt(st.nextToken()); if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0) break; N=f+e+d+(c+3)/4; y=5*d+u[c%4]; if(b>y)N+=(b-y+8)/9; x=36*N-36*f-25*e-16*d-9*c-4*b; if(a>x)N+=(a-x+35)/36; System.out.println(N); } }}

--------------------------------------------------------------------------------------------------

wrong 1: 00848175

--------------------------------------------------------------------------------------------------

#include<iostream>using namespace std;int main(){ int a1,a2,a3,a4,a5,a6; int b[4]={0,5,3,1}; while(1) { cin>>a1>>a2>>a3>>a4>>a5>>a6; if(a1==0&&a2==0&&a3==0&&a4==0&&a5==0&&a6==0)break; int total; int left1,left2; total=a6+a5+a4+(a3+3)/4; left1=5*a4+(a3/4)*5+b[(a3%4)]; if(left1<a2)total+=(a2-left1+8)/9; left2=36*total-a6*36-a5*25-a4*16-a3*9-a2*4; if(left2<a1)total+=(a1-left2+35)/36; cout<<total<<endl; }}

--------------------------------------------------------------------------------------------------

wrong2: BillyBob

--------------------------------------------------------------------------------------------------

#include<iostream>using namespace std;int main(){ int a1,a2,a3,a4,a5,a6; int extra1,extra2,b; int n; while(cin>>a1>>a2>>a3>>a4>>a5>>a6 && (a1 || a2 || a3 || a4 || a5 || a6)) { n=0;extra1=extra2=0; n+=a6+a5+a4+(a3+3)/4; extra2=a4*5; switch(a3%4) { case 0:break; case 1:extra2+=5;break; case 2:extra2+=3;break; case 3:extra2+=1;break; } if (a2>=extra2) { n+=(a2-extra2+8)/9;; } else { a2=0; extra2-=a2; } extra1=36*n-a6*36-a5*25-a4*16-a3*9-a2*4;// cout<<a1<<" "<<extra1<<endl; if (a1>=extra1) { n+=(a1-extra1+35)/36; } cout<<n<<endl; }}

--------------------------------------------------------------------------------------------------

wrong3: rain2whu

--------------------------------------------------------------------------------------------------

#include<stdio.h>main(){ int a1,a2,a3,a4,a5,a6,sum = 0,left2 = 0,left1 = 0; while(1) { scanf("%d %d %d %d %d %d",&a1,&a2,&a3,&a4,&a5,&a6); if(a1 == 0 && a2 == 0 && a3 == 0 && a4 == 0 && a5 == 0 && a6 == 0) break; sum = sum + a6 + a5 + a4 + (a3 + 3) / 4; if(a3 % 4 == 1) { left2 = 5; left1 = 27; } if(a3 % 4 == 2) { left2 = 3; left1 = 18; } if(a3 % 4 == 3) { left2 = 1; left1 = 9; } left2 = left2 + 5 * a4; if(a2 > left2) sum = sum + (a2 - left2 + 8) / 9; a1 = a1 - (sum * 36 - a6 * 36 - a5 * 25 - a4 * 16 - a3 * 9 - a2 * 4); if(a1 > 0) sum = sum + (a1 + 35) / 36; printf("%d\n",sum); }}

--------------------------------------------------------------------------------------------------

wrong4: 00848235

--------------------------------------------------------------------------------------------------

##include<iostream>

using namespace std;int num(int a[6]);int main(){ int a[6]; for(;;) { for(int i=0;i<6;++i) cin>>a[i]; if((a[0]||a[1]||a[2]||a[3]||a[4]||a[5])==0) {cout<<"Hello!";break;} else cout<<num(a)<<endl; } return 0;}int num(int a[6]){ int n=0,b,m; switch(a[2]%4) { case'0':b=0; case'1':b=5; case'2':b=3; case'3':b=1; } n=n+a[5]+a[4]+a[3]+(a[2]+3)/4; if(a[1]>5*a[3]+b) n=n+(a[1]-5*a[3]-b+8)/9; m=a[0]-36*(n-a[5])-25*a[4]-16*a[3]-9*a[2]-4*a[1]; if(m>0) n=n+(m+35)/36; return n;}

--------------------------------------------------------------------------------------------------

wrong5: wesley

--------------------------------------------------------------------------------------------------

#include<stdio.h>int main(){ int n,a,b,c,d,e,f,y,x; int u[4] = {0,5,3,1}; while(1) { n = 0; scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f); if(a == 0 && b == 0 && c == 0 && d == 0 && e == 0 && f == 0) break; n = f + e + d + (c + 3) / 4; y = 5 * d + u[c % 4]; if(b > y) n += (b - y + 8) / 9; x = 36 * n - 25 * e - 16 * d - 9 * c - 4 * b; if(a > x) n += (a - x + 35) / 36; printf("%d\n",n); } return 0;}

--------------------------------------------------------------------------------------------------