-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinBag.java
More file actions
42 lines (37 loc) · 1021 Bytes
/
MinBag.java
File metadata and controls
42 lines (37 loc) · 1021 Bytes
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
package AlgoClass;
// T38
public class MinBag {
public static int minBag(int apple) {
if (apple < 0) {
return -1;
}
int maxEight = apple / 8;
int cnt = -1;
while (maxEight >= 0) {
int rest = apple - maxEight * 8;
if (rest % 6 == 0) {
cnt = maxEight + rest / 6;
break;
}
maxEight--;
}
return cnt;
}
public static int minBagAwesome(int apple) {
if (apple < 0 || (apple & 1) != 0) {
return -1;
}
if (apple < 18) {
return apple == 0 ? 0 : (apple == 6 || apple == 8) ? 1 :
(apple == 12 || apple == 14 || apple == 16) ? 2 : -1;
}
return (apple - 18) / 8 + 3;
}
public static void main(String[] args) {
int totalCnt = 200;
for (int i = 1; i <= 200; i++) {
var ans = minBag(i);
System.out.println(i + ": " + ans);
}
}
}