Air in the Balloons - Code Vita 2017 | Round 1

 Air in the balloons

 Problem:

You have been given 'N' number of spherical Balloons of different radius when filled. You have to fill one balloon per day and the last balloon will be filled on Nth day. There is some rate of air reduction 'K' per day from each balloon. Fill the balloons in such an order so that the sum of the volume of all the balloons is maximum on the day when all the balloons are filled.

Input Format:  First Line is an integer N giving the number of balloons.  Second line gives space separated N positive real numbers with up to 1 decimal place giving the radii of the balloons.   Third line gives K, the rate of reduction in the volume of air as a percentage.

Output Format:  Maximum sum of volumes of all the balloons on the Nth day when all the balloons are filled. Take 3.14 as the value of PI and give the answer to two decimal places (truncated by ignoring all the decimals from third onwards). Note that the truncation should happen only after computing the volume of all the balloons on the final day to maximum precision.

Constraints: 

 Number of balloons <= 10  Radius of balloons <=200

Example 1  

Input  
5
 8 4 6 10 3  1 0

Output 
 7117.88

Explanation  
If we fill the balloons in the order 3, 4, 6, 8, 10, their volumes on the fifth day are respectively  7 4.165544  1 95.33312  7 32.4992 1929.216  4 186.666667  A nd their sum is 7117.880531. Truncating the value two decimal places, we obtain 7117.88

Example 2  

Input  
7
3 .5 9 4 6.6 7 11 9.1  1 2.5

Output  
12555.35

Explanation  
If we inflate the balloons in the order 3.5 4 6.6 7 9 9.1 11, their volumes on the seventh day would be respectively  8 0.56025567  1 37.4322396 705.5574848  9 62.0256771  2 336.74875  2 760.581763 5572.453333 The sum of these volumes is 12555.3595 and truncating to two decimal places, we obtain 12555.35

Program

#include <stdio.h>
double rate(double y,float m,int k)
{
    for(int i=k;i>=1;i--)
    {
     y=y-y*(m/100);
    }
return y;
}
int main() {
int n,i,j;
double v,b[1000],t,v1,sum=0;
float a[1000],x;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%f ",&a[i]);
scanf("%f ",&x);
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j])
{
   t=a[i];
   a[i]=a[j];
   a[j]=t;
}
for(i=0;i<n;i++)
{
v=0;
v=(4*3.14*a[i]*a[i]*a[i])/3;
b[i]=rate(v,x,n-(i+1));
}
for(i=0;i<n;i++)
sum=sum+b[i];
printf("%.2f ",sum);
return 0;

}

You can also run it online 
IDE: https://ide.geeksforgeeks.org/iNcfre3Isa

our feedback are always welcome! If you have any doubt you can contact me or leave a comment!! Cheers!!!

Related Links 
One Egg :https://codepiggy.blogspot.com/2019/05/one-egg-code-vita-2017-round-2.html

No comments:

Post a Comment

Super Market Problem | TCS Code Vita 2023 - Zone 1 | Super Market TCS Code Vita 2023 Solution | Code Vita 2023 | Code Vita 2023 season 11 solution

 Problem Description: In a Super market we will find many variations of the same product. In the same way we can find many types of rice bag...