JMPKANG - Editorial

PROBLEM LINK:
Practice

Author: Rupanjan Hari

Tester: Rupanjan Hari

DIFFICULTY
: Easy

PREREQUISITES
: Math

QUICK EXPLANATION

This problem is like the problem of two cars running at two different velocities, where you have to determine when will they meet. The story has twist in this case, the starting position are different and you have to print ‘YES’ if they ever meet otherwise ‘NO’.

EXPLANATION

The starting positions and velocities of the car will be giver alternately. Receive them and calculate their pace.
The code snippet (written in C) below shows the checking process.

if (v1<=v2)
{
if (x1==x2 && v1==v2)
printf(“YES”);
else
printf(“NO”);
}
else
{
//Run the loop to detect the whether the Kangaroo’s will cross each other. If so set the ‘flag’ otherwise keep it as ‘0’
}
if (flag==1)
printf(“YES”);
else
printf(“NO”);

Run this code for each input x1,v1,x2,v2.

SOLUTION:
click here to see the solution