This year Chef is participating in a Dancing competition. Chef wants to find the minimum number of moves required to reach his partner. Can you help him find this number?

 

This year Chef is participating in a Dancing competition. The dance performance will be done on a linear stage marked with integral positions. Initially, Chef is present at position X and Chef's dance partner is at position Y. Chef can perform two kinds of dance moves.  If Chef is currently at position k, Chef can:  Moonwalk to position k+2, or Slide to position k−1 Chef wants to find the minimum number of moves required to reach his partner. Can you help him find this number?







OURSHOPKEEPER












#include <iostream>
using namespace std;
int main()
{
    //x y  k+2  k-1
    int X, Y, T, o;
    cin >> T;
    while (T--)
    {

        int count = 0;
        cin >> X >> Y;

        while (X != Y)
        {
            if (Y > X) // 8
            {
                X = X + 2;
                ++count;
                //  cout << count << " ";
            }
            else if (Y < X)
            { // 8
                X = X - 1;
                ++count;
                // cout << count << " ";
            }
            else
            {
                break;
            }
        }
        cout << count << endl;
    }
}





    


Click on the above button to download the code.



Post a Comment

If you have furthur QUERIES please let us know

Previous Post Next Post