We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
There are 2 cases :
I) If one is ahead and faster they never meet "NO".
II)If one is behind and faster they meet only if for some time k
x1 + k*v1 = x2 + k*v2 -> k = x2-x1/v2-v1
only if k is integer, when v2-v1 divides x2-x1.
C++ Solution
intmain(){intx1;intv1;intx2;intv2;cin>>x1>>v1>>x2>>v2;// ahead and faster //if((x2>x1&&v2>=v1)||(x1>x2&&v1>=v2))cout<<"NO";else// behind and faster // if(!((x2-x1)%(v2-v1)))cout<<"YES";elsecout<<"NO";return0;}
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
There are 2 cases : I) If one is ahead and faster they never meet "NO". II)If one is behind and faster they meet only if for some time k x1 + k*v1 = x2 + k*v2 -> k = x2-x1/v2-v1 only if k is integer, when v2-v1 divides x2-x1.
C++ Solution