-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay50.java
More file actions
47 lines (37 loc) · 1.34 KB
/
Day50.java
File metadata and controls
47 lines (37 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public class Day50 {
public static void main(String[] args) {
int[] logs = { /* Your array of logs */ };
int axes = /* Number of axes */;
int logCuttingStandCapacity = /* Capacity of log cutting stand */;
int result = findMinimumMoves(logs, axes, logCuttingStandCapacity);
System.out.println("Minimum moves to determine the limit: " + result);
}
private static int findMinimumMoves(int[] logs, int axes, int logCuttingStandCapacity) {
int left = 1;
int right = logCuttingStandCapacity;
while (left <= right) {
int mid = left + (right - left) / 2;
if (canCutLogs(logs, axes, logCuttingStandCapacity, mid)) {
right = mid - 1;
} else {
left = mid + 1;
}
}
return left;
}
private static boolean canCutLogs(int[] logs, int axes, int logCuttingStandCapacity, int mid) {
int moves = 0;
for (int i = 0; i < logs.length; ) {
int currentLogs = 0;
while (i < logs.length && currentLogs + logs[i] <= mid) {
currentLogs += logs[i];
i++;
}
moves++;
if (moves > axes) {
return false; // Axe is broken, cannot use it again
}
}
return true;
}
}