SlayingDeer
SRM 182 · 2004-02-07 · by dgarthur
Problem Statement
Although TopCoder member Running Wild is a vegetarian, he has recently decided that he would eat venison if he could catch a deer himself. Before committing too much time and effort to this endeavor, Running Wild would like to estimate his chances at success. To do this, he assumes that he will run at a constant speed of A meters per minute without ever getting tired. Similarly, a deer will run at a constant speed of B meters per minute, but after every 30 minutes of running, it must stop and rest for 15 minutes. Finally, Running Wild also assumes that he will begin at a given distance of C meters behind the deer, and that they will always be running in the same fixed direction.
Create a class SlayingDeer that contains a method getTime, which is given an
Notes
- If Running Wild and the deer are at precisely the same position, then Running Wild is considered to have caught the deer.
Constraints
- A and B will be between 1 and 1000 inclusive.
- C will be between 1 and 100000 inclusive.
5 4 20 Returns: 20
Running Wild gains one meter per minute over the first 20 minutes before catching the deer.
5 4 47 Returns: 34
As in the previous example, Running Wild will gain 1 meter per minute for the first 30 minutes. Then, however, the deer stops and rests. Running Wild gains 5 meters per minute while the deer is resting. Note that the answer is rounded up.
10 17 1 Returns: -1
133 198 7515 Returns: 7515
1 1000 15819 Returns: -1
10 15 1 Returns: -1
Boundary case - deer and Running Wild are exactly even.
1 1 100000 Returns: 300010
Boundary case - Running Wild catches up in about the maximum time.
Submissions are judged against all 87 archived test cases, of which 7 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SlayingDeer with a public method int getTime(int A, int B, int C) · 87 test cases · 2 s / 256 MB per case