public int woodCut(int[] L, int k) {
if (L == null || L.length == 0) return 0;
int lb = 0, ub = Integer.MAX_VALUE;
while (lb + 1 < ub) {
int mid = lb + (ub - lb) / 2;
if (C(L, k, mid)) {
lb = mid;
} else {
ub = mid;
}}
return lb;
} // whether it cut with length x and get more than k pieces
private boolean C(int[] L, int k, int x) {
int sum = 0;
for (int l : L) {
sum += l / x;
}
return sum >= k;
}
Wood Cut(二分查找)
最新推荐文章于 2024-07-26 13:45:00 发布