The Corona virus

Corona Virus is really strange.

A strange species of Corona virus spreads as follows :-

  • It spreads linearly and only in positive x direction.
  • Every tth second it does one of the two things -
    • Jump exactly 2t units taking 1 second thus increasing its position by 2t units.
    • Do not move at all.

Example: If it takes a jump at time T=2 sec then it's position will increase by 22=4 units.

At time T=0 , Corona starts spreading from the position x=0 and Tango is sleeping at position x=N.You have to tell if Corona can reach to Tango or not. If YES minimize the total time it takes and tell all such time instances t at which corona jumps.

Example:

Input:  n = 3

Output:

YES 2 0 1

Approach:

C++

#include <bits/stdc++.h>
using namespace std;
int main()
{

    int n = 3;

    cout << "YES" << endl;

    cout << __builtin_popcount(n<< endl;
    int a[32] = {0};
    int i = 0;
    while (n > 0)
    {
        a[i] = n % 2;
        n /= 2;
        i++;
    }
    for (int j = 0j < ij++)
    {
        if (a[j] == 1)
            cout << j << " ";
    }
    return 0;
}


No comments:

Post a Comment