Statistics

Problem Statement for "Musical"

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

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

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

  3. 26

    100.0

    Returns: "N"

  4. 3

    13.33333333

    Returns: "A"

  5. 7

    1.0

    Returns: "G"

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

  7. 2

    97.5001

    Returns: "B"

  8. 2

    97.4999999

    Returns: "A"

  9. 26

    6.32

    Returns: "S"

  10. 26

    6.3333

    Returns: "R"

  11. 26

    30.0

    Returns: "N"

  12. 3

    95.01

    Returns: "B"

  13. 6

    6

    Returns: "D"

  14. 5

    5.01

    Returns: "C"

  15. 4

    4

    Returns: "B"

  16. 3

    3

    Returns: "A"

  17. 2

    2

    Returns: "B"

  18. 11

    93.11360627157264

    Returns: "E"

  19. 4

    82.43353272623155

    Returns: "D"

  20. 16

    94.73354925417038

    Returns: "G"

  21. 12

    48.85784498751542

    Returns: "J"

  22. 2

    68.07855395827394

    Returns: "B"

  23. 20

    70.8611484776482

    Returns: "R"

  24. 19

    3.801045115813053

    Returns: "N"

  25. 21

    59.67468011687829

    Returns: "D"

  26. 12

    50.81878818026858

    Returns: "H"

  27. 2

    5.035596525341242

    Returns: "A"

  28. 6

    8.703510843974115

    Returns: "B"

  29. 6

    45.57191009502199

    Returns: "E"

  30. 20

    48.72814037961462

    Returns: "S"

  31. 22

    2.4714514233909637

    Returns: "H"

  32. 2

    40.51384648826714

    Returns: "B"

  33. 24

    72.27015306351026

    Returns: "H"

  34. 22

    10.454591349893066

    Returns: "M"

  35. 22

    71.18307498198075

    Returns: "A"

  36. 2

    58.729590324359236

    Returns: "B"

  37. 11

    32.06796037119692

    Returns: "F"

  38. 13

    21.950078722452687

    Returns: "C"

  39. 4

    96.39913781226532

    Returns: "C"

  40. 17

    92.37193925720291

    Returns: "M"

  41. 19

    57.882195261500314

    Returns: "G"

  42. 21

    10.334375459755545

    Returns: "R"

  43. 21

    25.129838215553992

    Returns: "F"

  44. 23

    96.20017182231156

    Returns: "U"

  45. 7

    37.31630188409941

    Returns: "B"

  46. 10

    23.442684470686224

    Returns: "E"

  47. 21

    16.49982024781516

    Returns: "L"

  48. 4

    70.38569894825125

    Returns: "C"

  49. 19

    27.080594596354683

    Returns: "O"

  50. 9

    1.622759706506978

    Returns: "C"

  51. 14

    90.57025603905608

    Returns: "L"

  52. 21

    77.85968940211978

    Returns: "Q"

  53. 12

    83.75177773745783

    Returns: "E"

  54. 14

    29.063417048572123

    Returns: "K"

  55. 18

    81.3810101977034

    Returns: "D"

  56. 21

    3.902506663747165

    Returns: "P"

  57. 4

    62.26724378357364

    Returns: "D"

  58. 9

    7.886449303491099

    Returns: "C"

  59. 9

    15.858421492892282

    Returns: "H"

  60. 17

    84.88476130187354

    Returns: "M"

  61. 20

    63.7338434125554

    Returns: "I"

  62. 25

    24.89741776988311

    Returns: "T"

  63. 26

    67.84381998604206

    Returns: "X"

  64. 14

    43.04228911630176

    Returns: "I"

  65. 16

    43.574054990036345

    Returns: "C"

  66. 24

    60.76295388997509

    Returns: "S"

  67. 3

    51.419011033556586

    Returns: "B"

  68. 23

    56.0

    Returns: "H"

  69. 25

    99.98

    Returns: "O"

  70. 2

    5.0

    Returns: "A"

  71. 23

    89.37584682273902

    Returns: "U"

  72. 3

    12.0

    Returns: "A"

  73. 26

    1.0

    Returns: "A"

  74. 14

    57.5723

    Returns: "J"

  75. 2

    6.0

    Returns: "A"


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: