TopCoder problem "Musical" used in SRM 247 (Division I Level One)



Problem Statement

    n children walk around a circle with n-1 evenly-spaced chairs. When the music stops, each one tries to get to the nearest chair. One of them is bound to fail thus providing a lesson about life. We want to identify the loser.

The children start evenly spaced around the circle, with the first child, A, located right next to a chair. The child who follows A as they walk around the circle is B, the one who follows B is C, etc. The children all start walking when the music starts at a speed that will get them all the way around the circle in 10 seconds. When the music stops, they each try to get to the nearest chair.

Create a class Musical that contains a method loser that is given n (the number of children) and time (the number of seconds the music plays). The method should return the name of the loser as a String containing just one uppercase letter.

It may be helpful to note that the child who is farther from any chair than each other child is always the loser.

 

Definition

    
Class:Musical
Method:loser
Parameters:int, double
Returns:String
Method signature:String loser(int n, double time)
(be sure your method is public)
    
 

Constraints

-n will be between 2 and 26 inclusive.
-time will be between 1.0 and 100.0 inclusive.
-For all values within 1.0 E-9 of time the same child would be the loser.
 

Examples

0)
    
3
1.2
Returns: "B"
Starting from their original positions they walk for 1.2 seconds. When the music stops the closest chair to A is the first chair, the one he started at. Meanwhile B has moved to the point where now that chair is also the closest chair for him. But A is closer than B so B is the loser. (C is closest to the second chair and has no competition for that one.)
1)
    
3
12.0
Returns: "A"
The children walk all the way around the circle and a little farther before the music stops. The situation is almost the same now as in the previous case, with A and B racing for the first chair, but this time A is farther away than B.
2)
    
26
100.0
Returns: "N"
3)
    
2
15.0
Returns: "A"
The 2 children start out with A next to the chair and B on the other side of the circle. After 15 seconds, they have gone around the circle one and a half times, so B is next to the chair and A is the loser.

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7222&pm=4495

Writer:

dgoodman

Testers:

PabloGilberto , lbackstrom , brett1479

Problem categories:

Math