| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
感谢大神的1000组测试数据 我用Java写的代码 贴上来import java.util.*;
/**
* 赵亮亮做完此题感觉很爽 因为证明我还是有耐心的好孩纸
* @author Administrator
*
*/
public class Packets {
public static int box = 0;
public static List<Integer> list = new ArrayList<Integer>();
public static void main(String[] args) {
int[] array = new int[6];
Scanner cin = new Scanner(System.in);
while (cin.hasNext()) {
for (int i = 0; i < 6; i++) {
array[i] = cin.nextInt();
}
if (ifExit(array))
break;
int temres = baseBox(array);
list.add(temres);
}
Iterator it = list.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
/**
* 当array元素遍历过一遍时返回包装数目
*
* @param array
* @return
*/
public static int baseBox(int[] array) {
int num = 0;
// num+=array[3]+array[4]+array[5]+Math.ceil((array[2]*1.00)/4);
// 处理6*6的物品 每个盒子只能装一个物品
num += array[5];
// 处理5*5的物品 每个盒子只能装一个物品
if (array[4] != 0) {
num += array[4];
array[0] -= 11 * array[4];
if (array[0] < 0) {
array[0] = 0;
}
}
// 处理4*4的物品 每个盒子只能装一个物品 然后先考虑2*2 其次1*1
if (array[3] != 0) {
num += array[3];
int temp = array[1] - array[3] * 5;
if (temp > 0) {
array[1] = temp;
} else {
int tempSqu = array[3] * 20 - array[1] * 4;
array[1] = 0;
if (tempSqu > 0) {
array[0] -= tempSqu;
}
if (array[0] < 0) {
array[0] = 0;
}
}
}
// 处理3*3的物品 每个盒子只能装一个物品 然后先考虑2*2 其次1*1
if (array[2] != 0) {
int temp = (int) Math.ceil((array[2] * 1.00) / 4);
num += temp;
int temp2 = 4 - array[2] % 4;
if (temp2 != 4) {
int tempSquare = temp2 * 9; // temSquare 放了3*3后剩余的面积
int temp3 = 0; // temp3是实际放了几个3*3
if (array[1] != 0) {
temp3 = array[1]; // temp3 是实际放了几个3*3 这一步是初始化temp3
array[1] -= (tempSquare / 4 - 1);
if (array[1] < 0) {// 这样代表把2*2全部用完了
array[1] = 0;
} else { // 这样代表2*2还有剩余
temp3 = (tempSquare / 4 - 1);
}
array[0] -= (tempSquare - temp3 * 4);
if (array[0] < 0) {
array[0] = 0;
}
} else {
array[0] -= tempSquare;
if (array[0] < 0) {
array[0] = 0;
}
}
} else {
array[2] = 0;
}
}
// 处理2*2的物品 每个盒子只能装一个物品
if (array[1] != 0) {
int temp = (int) Math.ceil((array[1] * 1.00) / 9);
num += temp;
int temp2 = 9 - array[1] % 9;
if (temp2 != 9) {
array[0] -= temp2 * 4;
if (array[0] < 0) {
array[0] = 0;
}
array[1] = 0;
} else {
array[1] = 0;
}
}
// 处理1*1的物品 每个盒子只能装一个物品
if (array[0] != 0) {
int temp = (int) Math.ceil((array[0] * 1.00) / 36);
num += temp;
}
return num;
}
public static boolean ifExit(int[] array) {
boolean res = true;
for (int i = 0; i < 6; i++) {
if (array[i] != 0)
res = false;
}
return res;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator