The Jumping Kangaroos
All submissions for this problem are available.
There are two kangaroos on an x-axis ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location and moves at a rate of meters per jump. The second kangaroo starts at location and moves at a rate of meters per jump. Given the starting locations and movement rates for each kangaroo, can you determine if they'll ever land at the same location at the same time?
A single line of four space-separated integers denoting the respective values of , , , and .
YES if they can land on the same location at the same time; otherwise, print
Note: The two kangaroos must land at the same location after making the same number of jumps.
Sample Input 0
0 3 4 2
Sample Output 0
The two kangaroos jump through the following sequence of locations:
Thus, the kangaroos meet after jumps and we print YES.
Sample Input 1
0 2 5 3
Sample Output 1
The second kangaroo has a starting location that is ahead (further to the right) of the first kangaroo's starting location (i.e., ). Because the second kangaroo moves at a faster rate (meaning ) and is already ahead of the first kangaroo, the first kangaroo will never be able to catch up. Thus, we print NO.
|Tags||easy, hrupanjan, math, solution|
|Time Limit:||1 sec|
|Source Limit:||5000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, RUBY, PHP, NODEJS, PERL, FORT, JS, PERL6, TEXT, PYP3|
Fetching successful submissions
If you are still having problems, see a sample solution here.