Computer Science, asked by jonnalagaddanaveen, 1 day ago

Single File Programming Question Hari was forced to participate in a game where he is up against an opponent, Ram. Both choose a random number. Suppose Hari chose X and Ram chose Y. The number of turns is given by the referee. Whenever the turn number is odd, X is multiplied by 2 and if the turn number is even, Y is multiplied by 2. The task is to find the value of max(Finalx, Finaly) / min(FinalX, Finaly) after they complete P turns. Given three positive integers X, Y and P, where P denotes the number of turns, find the value after P turns. Example 1

Answers

Answered by shadabsdr2005
0

Answer:

2 be ram y is charitr answer 4

Answered by shilpa85475
1

Choose p=0 and indices {1}. Now AA becomes [2,6,10].

Choose p=1 and indices {1,2}. Now AA becomes [0,4,10].

Choose p=1 and indices {3}. Now A becomes [0,4,8].

Choose p=2 and indices {2}. Now A becomes [0,0,8].

 Choose p=3 and indices {3}. Now A becomes [0,0,0].

Explanation:  

import java.util.*;

import java.lang.*;

import java.io.*;  

class abc

{

   public static void main (String[] args) throws java.lang.Exception

   {

       

       Scanner sc = new Scanner(System.in);

       int t = sc.nextInt();

       

       while(t-->0){

           int n = sc.nextInt();

           int k = sc.nextInt();

           int arr[] = new int[n];

           for(int i=0;i<n;i++){

               arr[i] = sc.nextInt();

           }            int sum[] = new int[33];            for(int i=0;i<n;i++){

               int x = arr[i];

               int j = 32;

               while(x>0){

                   sum[j] += (x%2);

                   j--;

                   x /= 2;

               }

           }

           int cnt=0;

           for(int i=0;i<33;i++){

               if(sum[i]%k==0){

                   cnt+= sum[i]/k;

               }else{

                   cnt+= sum[i]/k;

                   cnt+=1;

               }

           }

           System.out.println(cnt);

       }

   }

}

 

Similar questions