Connection Status:
Competition Arena > EyeDrops
SRM 167 · 2003-10-14 · by dgoodman · Math
Class Name: EyeDrops
Return Type: double
Method Name: closest
Arg Types: (int, int)
Problem Statement

Problem Statement

Note to plugin users: There is an image in the problem examples. Please use the applet to view it.

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.

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
0)
8
2
Returns: 720.0

You can take one dose when you wake up, and the next one 12 hours later.

1)
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.

2)
9
3
Returns: 450.0

Take your medicine when you wake up, when you go to sleep, and halfway in between.

3)
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.

4)
23
1
Returns: 1440.0

Submissions are judged against all 40 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class EyeDrops with a public method double closest(int sleepTime, int k) · 40 test cases · 2 s / 256 MB per case

Submitting as anonymous