HingedDoor
SRM 275 · 2005-11-30 · by NeverMore
Problem Statement
Create a class HingedDoor which contains a method numSwings. The method takes an
Constraints
- initialAngle will be between 0 and 90, inclusive.
- reduction will be between 2 and 10, inclusive.
50 2 Returns: 4
In this example, the door begins with an initial angle of 50 degrees. Then, the door will swing through a reduced angle of (1/2)*(50) = 25 degrees on the first swing. At this point, the door will reverse direction, and swing through an angle of (1/2)*(25) = 12.5 degrees. Continuing in this way, the door will swing once more through (1/2)*(12.5) = 6.25 degrees, and then through (1/2)*(6.25) = 3.125 degrees. At this point, the door will come to rest. Therefore, the correct return value is 4, since the door took 4 swings before coming to rest.
45 6 Returns: 2
23 3 Returns: 2
3 3 Returns: 0
Careful! The initial angle is already below 5 degrees, so the door won't swing at all, but rather, return to rest position immediately.
73 5 Returns: 2
Submissions are judged against all 90 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class HingedDoor with a public method int numSwings(int initialAngle, int reduction) · 90 test cases · 2 s / 256 MB per case