You are viewing a single comment's thread. Return to all comments →
Here is my java solution , it is may be big but it is easily understandable solution to beginners so
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x1 = sc.nextInt(); int v1 = sc.nextInt(); int x2 = sc.nextInt(); int v2 = sc.nextInt(); if((x2>x1)&&(v2>v1)||(x2==x1)||(v1==v2)) { System.out.print("NO"); } else if((x2>x1)&&(v1>v2)||(x2==x1)||(v1==v2)) { for(x1=x1,x2=x2;x1<=x2;x1=x1+v1,x2=x2+v2) { if(x1==x2) { System.out.print("YES"); x1 = x1; x2 = x2; break; } } if(x1!=x2) System.out.print("NO"); } else if((x1>x2)&&(v2>v1)||(x2==x1)||(v1==v2)) { for(x1=x1,x2=x2;x2<=x1;x1=x1+v1,x2=x2+v2) { if(x1==x2) { System.out.print("YES"); x1 = x1; x2 = x2; break; } } if(x1!=x2) System.out.print("NO"); } else if((x1>x2)&&(v1>v2)||(x2==x1)||(v1==v2)) { for(x1=x1,x2=x2;x1<=x2;x1=x1+v1,x2=x2+v2) { if(x1==x2) { System.out.print("YES"); x1 = x1; x2 = x2; break; } } if(x1!=x2) System.out.print("NO"); } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
Here is my java solution , it is may be big but it is easily understandable solution to beginners so