Kangaro

 Kangaro


Problem Description


"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 x1 and moves at a rate of v1 meters per jump. The second kangaroo starts at location x2 and moves at a rate of v2 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?


Input Format


A single line of four space-separated integers denoting the respective values of x1,v1 ,x2, and v2 .


Constraints


0 <= x1 < x2 <= 10000

1 <= v1 <= 10000

1 <= v2 <= 10000


Output Format


Print YES if they can land on the same location at the same time; otherwise, print NO.


Note: The two kangaroos must land at the same location after making the same number of jumps.


Sample Input


0 3 4 2


Sample Output


YES


Explanation


0->3->6->9->12

4->6->8->10->12


The two kangaroos jump through the following sequence of locations:


Thus, the kangaroos meet after jumps and we print YES.

Logic Test Case 1


Input (stdin)

0 3 4 2


Expected Output


YES

Logic Test Case 2


Input (stdin)

0 2 5 3


Expected Output


NO




CODE AREA

import java.util.*;

public class TestClass {

     public static void main(String[] args) { 

        Scanner s=new Scanner(System.in);

       int a,b,c,d;

       a=s.nextInt();

       b=s.nextInt();

       c=s.nextInt();

       d=s.nextInt();

       if((c>d)&&(a-b)%(c-d)!=0)

         System.out.println("YES");

       else

         System.out.println("NO");

    }

}


Post a comment

0 Comments