-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq1a.java
37 lines (33 loc) · 868 Bytes
/
q1a.java
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
/*
Scoring guidelines:
https://apcentral.collegeboard.org/media/pdf/ap23-sg-computer-science-a.pdf
*/
(a)
public int findFreeBlock(int period, int duration) {
int free = -1;
for (int i = 0; i < 60 - duration + 1; i++) {
int count =0 ;
for (int j = i; j < i+duration; j++) {
if (isMinuteFree(period, j)) {
count++;
}
if (count == duration) {
free = i;
}
}
}
return free;
}
(b)
public boolean makeAppointment(int startPeriod, int endPeriod, int duration) {
int s = 0;
for (int p = startPeriod; p < endPeriod+1; p++) {
if (findFreeBlock(p, duration) != -1) {
s = findFreeBlock(p, duration);
reserveBlock(p, s, duration);
return true;
} else {
return false;
}
}
}