RROUNDS - Colliding Race

Problem LInk : https://www.codechef.com/SMTC2020/problems/RROUNDS

Initially two people start from the same point of circular track and move in same direction. But as one has more speed than other so before completion of x rounds person with higher speed will cross the other person some y times.

When person with more speed relative to other person complete one round of track then it will must cross the person to move further.

Relative speed = abs(speed of 1st – speed of 2nd)

Let person with higher speed = v1
Let person with lower speed = v2

As person with higher speed have to cover x rounds so total time take:
Total time = x * Circumference of track / v1

In this total time how many time 1st person cover full track w.r.t 2nd persom is:
(relative speed * total time) / circumference of circle

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007

int main()
    ll test;
    cin >> test;
    while (test--)
        ll a, b, x, r;
        cin >> x >> r >> a >> b;
        ll relative_speed = abs(a - b);
        ll max_speed = max(a, b);
        ll ans = 0;
        //if both are at the end point when person with higher speed complete x    	  
        //rounds then crossing wil not occur so substract -1
        if ((x * relative_speed) % max_speed == 0)
        ans += ((x * relative_speed) / max_speed);
        cout << ans << endl;
    return 0;
1 Like

Thank you for the explanation.