Statistics

Problem Statement for "EyeDrops"

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.

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

  1. 8

    2

    Returns: 720.0

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

  2. 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.

  3. 9

    3

    Returns: 450.0

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

  4. 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.

  5. 23

    1

    Returns: 1440.0

  6. 9

    8

    Returns: 128.57142857142856

  7. 0

    50

    Returns: 28.799999999999997

  8. 0

    1

    Returns: 1440.0

  9. 6

    7

    Returns: 180.0

  10. 7

    7

    Returns: 170.0

  11. 8

    8

    Returns: 137.14285714285714

  12. 15

    10

    Returns: 60.0

  13. 10

    20

    Returns: 44.21052631578947

  14. 8

    3

    Returns: 480.0

  15. 0

    49

    Returns: 29.387755102040817

  16. 1

    49

    Returns: 28.75

  17. 2

    49

    Returns: 27.5

  18. 3

    49

    Returns: 26.25

  19. 4

    49

    Returns: 25.0

  20. 5

    49

    Returns: 23.75

  21. 6

    49

    Returns: 22.5

  22. 1

    7

    Returns: 205.7142857142857

  23. 8

    2

    Returns: 720.0

  24. 9

    8

    Returns: 128.57142857142856

  25. 23

    1

    Returns: 1440.0

  26. 23

    2

    Returns: 60.0

  27. 20

    2

    Returns: 240.0

  28. 6

    3

    Returns: 480.0

  29. 1

    5

    Returns: 288.0

  30. 0

    25

    Returns: 57.599999999999994

  31. 1

    3

    Returns: 480.0

  32. 14

    2

    Returns: 600.0

  33. 1

    2

    Returns: 720.0

  34. 4

    5

    Returns: 288.0

  35. 22

    4

    Returns: 40.0

  36. 6

    2

    Returns: 720.0

  37. 15

    2

    Returns: 540.0

  38. 10

    2

    Returns: 720.0

  39. 11

    2

    Returns: 720.0

  40. 7

    3

    Returns: 480.0


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: