Statistics

Problem Statement for "DogAndRabbit"

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

  1. 150

    100

    10

    5

    Returns: "YES"

  2. 100

    200

    20

    10

    Returns: "YES"

    The dog will catch the rabbit about 62 units away from the rabbit's home.

  3. 1

    100

    1

    0

    Returns: "NO"

    Here the dog is not so interested in the rabbit, so it stays in place.

  4. 0

    5

    1

    2

    Returns: "YES"

    The dog got the rabbit already.

  5. 1000000

    1000000

    1000000

    1000000

    Returns: "NO"

  6. 1000000

    1000000

    499999

    1000000

    Returns: "YES"

  7. 1000000

    1000000

    500000

    1000000

    Returns: "YES"

  8. 999999

    999997

    499999

    1000000

    Returns: "NO"

  9. 999995

    999997

    499999

    999998

    Returns: "YES"

  10. 999984

    999997

    499999

    999993

    Returns: "YES"

  11. 1

    1

    1

    5

    Returns: "YES"

  12. 1

    1

    1

    3

    Returns: "NO"

  13. 56

    86

    50

    96

    Returns: "YES"

  14. 50

    96

    53

    89

    Returns: "NO"

  15. 103

    194

    101

    161

    Returns: "YES"

  16. 103

    191

    108

    188

    Returns: "NO"

  17. 100

    211

    184

    473

    Returns: "YES"

  18. 100

    263

    137

    197

    Returns: "NO"

  19. 999994

    999996

    499999

    999999

    Returns: "YES"

  20. 1

    0

    0

    0

    Returns: "NO"

  21. 0

    1

    0

    0

    Returns: "YES"

  22. 0

    1

    0

    1

    Returns: "YES"

  23. 0

    1

    1

    0

    Returns: "YES"

  24. 0

    1

    1

    1

    Returns: "YES"

  25. 1

    0

    0

    1

    Returns: "YES"

  26. 1

    0

    1

    0

    Returns: "NO"

  27. 1

    0

    1

    1

    Returns: "NO"

  28. 1

    1

    0

    0

    Returns: "NO"

  29. 1

    1

    0

    1

    Returns: "YES"

  30. 1

    1

    1

    1

    Returns: "NO"

  31. 2

    499998

    499998

    1000000

    Returns: "YES"

  32. 265432

    234567

    234567

    999998

    Returns: "YES"

  33. 605801

    675735

    212998

    254659

    Returns: "NO"

  34. 100

    0

    0

    5

    Returns: "YES"

    The poor rabbit sleeps in front of his house, not aware of the dog.

  35. 200

    10

    5

    10

    Returns: "NO"

    The dog is too far away from the rabbit to catch it.

  36. 10

    10

    0

    0

    Returns: "NO"

  37. 0

    5

    0

    0

    Returns: "YES"

  38. 10

    0

    0

    10

    Returns: "YES"

  39. 10

    0

    0

    0

    Returns: "NO"

  40. 0

    5

    1

    0

    Returns: "YES"

  41. 100

    1

    0

    0

    Returns: "NO"

  42. 100

    100

    10

    4

    Returns: "YES"

  43. 20

    100

    0

    0

    Returns: "NO"

  44. 10

    0

    1

    0

    Returns: "NO"

  45. 100

    0

    0

    0

    Returns: "NO"


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: