Problem Statement
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
150
100
10
5
Returns: "YES"
100
200
20
10
Returns: "YES"
The dog will catch the rabbit about 62 units away from the rabbit's home.
1
100
1
0
Returns: "NO"
Here the dog is not so interested in the rabbit, so it stays in place.
0
5
1
2
Returns: "YES"
The dog got the rabbit already.
1000000
1000000
1000000
1000000
Returns: "NO"
1000000
1000000
499999
1000000
Returns: "YES"
1000000
1000000
500000
1000000
Returns: "YES"
999999
999997
499999
1000000
Returns: "NO"
999995
999997
499999
999998
Returns: "YES"
999984
999997
499999
999993
Returns: "YES"
1
1
1
5
Returns: "YES"
1
1
1
3
Returns: "NO"
56
86
50
96
Returns: "YES"
50
96
53
89
Returns: "NO"
103
194
101
161
Returns: "YES"
103
191
108
188
Returns: "NO"
100
211
184
473
Returns: "YES"
100
263
137
197
Returns: "NO"
999994
999996
499999
999999
Returns: "YES"
1
0
0
0
Returns: "NO"
0
1
0
0
Returns: "YES"
0
1
0
1
Returns: "YES"
0
1
1
0
Returns: "YES"
0
1
1
1
Returns: "YES"
1
0
0
1
Returns: "YES"
1
0
1
0
Returns: "NO"
1
0
1
1
Returns: "NO"
1
1
0
0
Returns: "NO"
1
1
0
1
Returns: "YES"
1
1
1
1
Returns: "NO"
2
499998
499998
1000000
Returns: "YES"
265432
234567
234567
999998
Returns: "YES"
605801
675735
212998
254659
Returns: "NO"
100
0
0
5
Returns: "YES"
The poor rabbit sleeps in front of his house, not aware of the dog.
200
10
5
10
Returns: "NO"
The dog is too far away from the rabbit to catch it.
10
10
0
0
Returns: "NO"
0
5
0
0
Returns: "YES"
10
0
0
10
Returns: "YES"
10
0
0
0
Returns: "NO"
0
5
1
0
Returns: "YES"
100
1
0
0
Returns: "NO"
100
100
10
4
Returns: "YES"
20
100
0
0
Returns: "NO"
10
0
1
0
Returns: "NO"
100
0
0
0
Returns: "NO"