Problem Statement |
| A dog is standing at point (0, 0), and a rabbit is standing at point (distanceToRabbit, 0). The rabbit starts running in a straight line toward his home, which is located at (distanceToHome + distanceToRabbit, 0). At the same time, the dog starts running in a straight line toward the rabbit.
The rabbit runs at a constant speed of rabbitSpeed units per second. This means that in t seconds, he travels rabbitSpeed * t units. The dog starts running at an initial speed of 0 and a constant acceleration of dogAcceleration units per second2. This means that in t seconds, he travels dogAcceleration * t2 / 2 units.
Return "YES" if the dog can catch the rabbit before the rabbit enters its home, or "NO" otherwise (all quotes for clarity). The dog can catch the rabbit if there exists a point (x, 0) such that x <= distanceToHome + distanceToRabbit, and both the dog and the rabbit are at that same point at the same time. |
|
Definition |
| Class: | DogAndRabbit | Method: | willCatch | Parameters: | int, int, int, int | Returns: | String | Method signature: | String willCatch(int distanceToRabbit, int distanceToHome, int rabbitSpeed, int dogAcceleration) | (be sure your method is public) |
|
|
|
|
Constraints |
- | distanceToRabbit will be between 0 and 1000000, inclusive. |
- | distanceToHome will be between 0 and 1000000, inclusive. |
- | distanceToRabbit and distanceToHome won't both be equal to 0. |
- | rabbitSpeed will be between 0 and 1000000, inclusive. |
- | dogAcceleration will be between 0 and 1000000, inclusive. |
|
Examples |
0) | |
| | Returns: "YES" | The dog will catch the rabbit about 62 units away from the rabbit's home. |
|
|
1) | |
| | Returns: "NO" | Here the dog is not so interested in the rabbit, so it stays in place. |
|
|
2) | |
| | Returns: "YES" | The dog got the rabbit already. |
|
|
3) | |
| | Returns: "YES" | The poor rabbit sleeps in front of his house, not aware of the dog. |
|
|
4) | |
| | Returns: "NO" | The dog is too far away from the rabbit to catch it. |
|
|