Connection Status:
Competition Arena > Musical
SRM 247 · 2005-06-18 · by dgoodman · Math
Class Name: Musical
Return Type: String
Method Name: loser
Arg Types: (int, double)
Problem Statement

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.

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)
3
13.33333333
Returns: "A"
4)
7
1.0
Returns: "G"
5)
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.

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

Coding Area

Language: C++17 · define a public class Musical with a public method string loser(int n, double time) · 75 test cases · 2 s / 256 MB per case

Submitting as anonymous