In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Packing problem of the Java implementation is how, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Question:
The shape of the products made in a factory is cuboid, their height is h, length and width are equal, there are six models, their length and width are 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6 respectively. These products are usually packed in a 6 / 6 / h box and mailed to the customer. Because the postage is very expensive, the factory has to find ways to reduce the number of parcels shipped per order. They really need a good program to help them solve this problem so as to save money. Now this program is designed by you.
Input
The input file consists of several lines, each representing an order. The line in each order consists of six integers separated by spaces, which are the quantities of the six products from 1: 1 to 6: 6. The input file ends with a line of 6 zeros.
Output
In addition to the 6 zeros on the input line, each line in the input file corresponds to a line in the output file, and each line outputs an integer that represents the minimum number of packages required for the corresponding order.
For a box of 6 / 6, there can only be one box of 6 / 6 or 5 / 5 or 4 / 4 at most, so when we initialize the number of boxes we need, it is the sum of these boxes. For 3 / 3 boxes, we can put one or 2 or 3 or 4 boxes, which we can divide and mold to determine the number of boxes with 3 boxes, and then add it to the total number of boxes. The next thing we need is to stuff the 1x1 and 2x2boxes into the boxes needed in front, and then add the boxes when we can't finish them. We should first count the remaining space in the front boxes, and give priority to 2x2, because we can change the position of the extra 2x2s into four 11s, after all, the 11s can be filled anywhere as long as there is space. So when our box contains a 5: 5 box, then it can only be stuffed with 1: 1, a box that can be filled with 11 1: 1, and for a box with 4: 4, then we can also hold 5 2 / 2 boxes. Don't turn it into 1: 1, unless there is no way to hold 1: 1, for 3: 3, it can be based on the space left in a box after taking the mold. If there is only one 3x3 in a box, then there is still room for 3 3s. We know that we can put 5 2s and 7 1s. For boxes with 2 3s, we can put 3 2s and 6 1s. For boxes with 3 3s, we can only put 1 2s and 5 1s. In this way, we figure out how much space there is for 2x 2s and 1x 1s at this time. Then we put in the boxes, one by one, and we know that both 1x 1s and 2x 2s are finished. If we are not finished, we will add new boxes, or if we do not finish putting 1x 1s, and there is still room for 2x 2s, then we can convert each 2x 2s into four 11s. For the specific implementation, look at the following code. Due to the time constraint, no comments have been written.
Import java.io.BufferedInputStream
Import java.util.HashMap
Import java.util.Map
Import java.util.Scanner
Public class Test {
Public static void main (String args []) {
Scanner sc=new Scanner (new BufferedInputStream (System.in))
Boolean flag=true
Map map=new HashMap ()
Int kryp0
While (flag) {
Int n [] = new int [6]
N [0] = sc.nextInt ()
N [1] = sc.nextInt ()
N [2] = sc.nextInt ()
N [3] = sc.nextInt ()
N [4] = sc.nextInt ()
N [5] = sc.nextInt ()
If (n [0] = = 0n [1] = = 0n [2] = = 0n [3] = = 0,000n [4] = = 0,000n [5] = = 0) {
Flag=false
} else {
Map.put (k, n)
Kicking +
}
}
For (int iTuno Bandi)
< map.size();i++){ int[] vs=(int[])map.get(i); int boxNum=0; boxNum+=vs[3]+vs[4]+vs[5]; if(vs[2]>0) {
If (vs [2]% 4) {
BoxNum+=vs [2] / 4
} else {
BoxNum+=vs [2] / 431
}
}
Int for1=vs [4] * 11
Int for2=vs [3] * 5
If (vs [2]% 4) {
For1+=7
For2+=5
} else if (vs [2]% 4) {
For1+=6
For2+=3
} else if (vs [2]% 4) {
For1+=5
For2+=1
}
If (vs [0])
< for1){ vs[0]=0; }else{ vs[0]=vs[0]-for1; } if(vs[1]< for2){ if(vs[0]>0) {
If (4* (for2-vs [1])-vs [0] > = 0) {
Vs [0] = 0
} else {
Vs [0] = vs [0]-4* (for2-vs [1])
}
}
Vs [1] = 0
} else {
Vs [1] = vs [1]-for2
}
If (! (vs [0] = = 0&&vs [1] = = 0)) {
If (vs [1] > 0) {
If (vs [1]% 999) {
BoxNum+=vs [1] / 9
} else {
BoxNum+=vs [1] / 9: 1
If (vs [0] > (9-(vs [1]% 9)) * 4) {
If ((vs [0]-(9-(vs [1]% 9)) * 4)% 36 years / 0) {
BoxNum+= (vs [0]-(9-(vs [1]% 9)) * 4) / 36
} else {
BoxNum+= (vs [0]-(9-(vs [1]% 9)) * 4) / 36
}
}
}
} else if (vs [0] > 0) {
If (vs [0]% 36 years 0) {
BoxNum+=vs [0] / 36
} else {
BoxNum+=vs [0] / 369.1
}
}
}
System.out.println (boxNum)
}
}
}
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.