Problem Statement
After laser surgery, I was instructed to put drops in my eyes 6 times a day, spacing them as far apart as possible. Considering that I sleep for some period each day, it required some calculation to come up with an optimal schedule. Recognizing that I get similar instructions every time I get medication from the doctor, it became clear that a computer program was needed.
Create a class EyeDrops that contains a method closest that is given sleepTime, the number of hours that the patient sleeps each day, and k, the number of doses required each day. The method returns the number of minutes between the closest doses, when the schedule is chosen to make this period as large as possible. You should assume that the patient sleeps for the same continuous period each day.
The schedule that you choose will be applied for multiple days, so the period between closest doses may be between doses on different days.
Definition
- Class:
- EyeDrops
- Method:
- closest
- Parameters:
- int, int
- Returns:
- double
- Method signature:
- double closest(int sleepTime, int k)
- (be sure your method is public)
Notes
- The returned value must have a relative error of less than 1.0E-9
Constraints
- sleepTime must be between 0 and 23 inclusive
- k must be between 1 and 50 inclusive
Examples
8
2
Returns: 720.0
You can take one dose when you wake up, and the next one 12 hours later.
13
2
Returns: 660.0
You can take one dose when you wake up, then take the second dose 12 hours later. It would be a mistake to take one when you wake up and another when you go to sleep since they would then be only 7 hours apart.
9
3
Returns: 450.0
Take your medicine when you wake up, when you go to sleep, and halfway in between.
8
4
Returns: 320.0
You can take one does when you wake up, then every 320 minutes take another dose, with the fourth dose taken when you go to sleep.
23
1
Returns: 1440.0
9
8
Returns: 128.57142857142856
0
50
Returns: 28.799999999999997
0
1
Returns: 1440.0
6
7
Returns: 180.0
7
7
Returns: 170.0
8
8
Returns: 137.14285714285714
15
10
Returns: 60.0
10
20
Returns: 44.21052631578947
8
3
Returns: 480.0
0
49
Returns: 29.387755102040817
1
49
Returns: 28.75
2
49
Returns: 27.5
3
49
Returns: 26.25
4
49
Returns: 25.0
5
49
Returns: 23.75
6
49
Returns: 22.5
1
7
Returns: 205.7142857142857
8
2
Returns: 720.0
9
8
Returns: 128.57142857142856
23
1
Returns: 1440.0
23
2
Returns: 60.0
20
2
Returns: 240.0
6
3
Returns: 480.0
1
5
Returns: 288.0
0
25
Returns: 57.599999999999994
1
3
Returns: 480.0
14
2
Returns: 600.0
1
2
Returns: 720.0
4
5
Returns: 288.0
22
4
Returns: 40.0
6
2
Returns: 720.0
15
2
Returns: 540.0
10
2
Returns: 720.0
11
2
Returns: 720.0
7
3
Returns: 480.0