标签:[] sum ++ void bag tor print static class
public static void main(String[] args) {
List<Integer> tax = new ArrayList<>();
tax.add(70);
tax.add(55);
tax.add(40);
tax.add(30);
tax.add(20);
tax.add(10);
// 关税倒序排列
Collections.sort(tax, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o2.compareTo(o1);
}
});
int bagCnt = 0;
int taxSum = 0;
int bagLmt = 50;
for (Integer t : tax) {
if (t >= bagLmt) {
bagCnt++;
taxSum = 0;
} else {
if (taxSum + t > bagLmt) {
bagCnt++;
taxSum = t;
} else {
taxSum += t;
}
}
}
if(taxSum >0) bagCnt++;
System.out.println(bagCnt);
}
标签:[] sum ++ void bag tor print static class
原文地址:http://www.cnblogs.com/dreammyone/p/7371903.html