TopCoder problem "EyeDrops" used in SRM 167 (Division II Level One)



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

0)
    
8
2
Returns: 720.0
You can take one dose when you wake up, and the next one 12 hours later.
1)
    
9
3
Returns: 450.0
Take your medicine when you wake up, when you go to sleep, and halfway in between.
2)
    
23
1
Returns: 1440.0
3)
    
9
8
Returns: 128.57142857142856

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=1750

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4640&pm=1750

Writer:

dgoodman

Testers:

lbackstrom , brett1479

Problem categories:

Math