CIELRCPT - Editorial

Hi,

i have tried to solve using recursion

code follows,but not being accepted as solution

please help,thanks

int n,p,divi,rem,t;

int calc(int num){

if (num == 0)
	return 0;

divi = num / 2048;

rem = num % 2048;

if (divi > 0)
	t = divi + calc(rem);
else
	t = calc(2 * rem);

return t;

}

int main(){

scanf("%d", &n);

for (int i = 0; i < n; i++){
	scanf("%d", &p);
	printf("%d \n", calc(p));
}

return 0;

}

#include<stdio.h>
int main()
{
int t,p,count,key;
scanf("%d",&t);
while(t–)
{
scanf("%d",&p);
if((p%2048)==0)
{
count=p/2048;
printf("%d",count);
printf("\n");
}
else
{
count=count_1§;
if(p/2048>1)
{
key=p/2048;
count=count+(key-1);
printf("%d",count);
printf("\n");
}
else
{
printf("%d",count);
printf("\n");
}
}
}
return 0;
}
int count_1(int n)
{
int ctd;
while(n)
{
n=n&(n-1);
ctd++;
}
return ctd;
}
it satisfy every case but during submission wrong answer

easiest way to solve the problem

import java.util.*;

import java.lang.*;

import java.io.*;

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

	Scanner obj = new Scanner(System.in);
	int a[] = new int[12];
	
	for(int i=0;i<=11;i++){
	    a[i] = (int) Math.pow(2,i);
	}
	
	int n = obj.nextInt();
                          
	for(int i=1;i<=n;i++){
                
	    int p = obj.nextInt();
               
	    int k=0,l=0;                
                
	    while(a[k]<=p){
	        l=k;
	        k++;  
                    if(k==12){
                    break;}
	    } 
             
                
	    int count=0;
	    while(a[l]>=1){
	        
	        count= count+(p/a[l]);
                    p=p%a[l];
	        l=l-1;
                    if(l<0){
                    break;}
                    
	    }
	    
	   System.out.println(count);
	 }		
	    
	
}

}

i need to convert the set of number into “k”, “mil”, “bil” for my php website (Soundcloud downloader) when i implement this code the website automatically turns into error 500. Expert advice needed

I found one of the best solution for it, ie: convert decimal to binary and count the number of ones in it. that’s the answer.

for eg:

decimal: 253

binary: 11111101

no of ones: 7 that’s the answer.

For No > 2048, you have to use rest logic.

Thnx.

Hey i tried the code using DP but the solution is not being accepted ,
the code works for the sample test cases and any other test case that i can think of .
Please help
Here is the link to my code :
https://www.codechef.com/viewsolution/14492082

can any one please check my code .I don’t know what is wrong it passed all sample tests.
https://www.codechef.com/viewsolution/17515413

Hello, guys, I have a website for downloading music from SoundCloud.
http://soundcloudmp3downloader.com/

And I hope u could help me… how can I get the information about bitrate of SC tracks?
is it possible? any idea?

My solution is a bit different and is very short if you are using C++ and stl as your tool to solve the problem
It uses a greedy approach to find the nearest value just smaller than or equal to n from the menu list.

    while (n > 0) {
        long nearest = upper_bound(menuList.begin(), menuList.end(), n) - menuList.begin();
        n -= menuList[nearest - 1];
        ++count;
    }

Here menuList is an array of the powers of 2 up to the required item - [1,2,4,8…]

int price[12] = {1, 2, 4, 8, 16, 32,
64, 128, 256, 512, 1024, 2048};

int t, p, c;
cin >> t;

for (int k = 0; k < t; k++)
{
    c = 0;
    cin >> p;
    while(p != 0) 
    {
        for (int i = 11; i >= 0; i--)
        {
            if (p >= price[i])
            {
                p -= price[i];
                c++;
                break;
            }
        }
    }
    cout << c << endl;
}

if someone interested in dynamic programming solution

#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>



using namespace std;
  #define MAX 1000007
   vector<int>v(12);
   vector<int>dp(100002,-1);


 int recu(int p)
    {
      if(p==0)
       return 0;
       if(p<0)
       return MAX;
    
      if(dp[p]!=-1)
       return dp[p];
       int q=MAX;
       for(int i=0;i<12;i++)
       {
        q=min(q,recu(p-v[i])+1);
       }
      return dp[p]=q;
    }


  int main()
        {
        int t,p;
        cin>>t;
        
        dp[0]=0;
        dp[1]=1;
        for(int i=0;i<12;i++)
        {
          v[i]=(1<<i);
        }
        
        while(t--)
        { 
            int ans=0;
           cin>>p;
     
           ans=recu(p);
          cout<<ans<<"\n";
    
       }
    return 0;
    }

link text