Showing posts with label competitive coding in C. Show all posts
Showing posts with label competitive coding in C. Show all posts

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

Sheldon Cooper and his beverage paradigm - Code Vita 2014 | round 1

Sheldon Cooper and his beverage paradigm

Sheldon Cooper, Leonard Hofstadter and Penny decide to go for drinks at Cheese cake factory. Sheldon proposes to make a game out of this. Sheldon proposes as follows, 
  • To decide the amount of beverage they plan to consume, say X.
  • Then order for a random number of different drinks, say {A, B, C, D, E, F} of quantities {a, b, c, d, e, f} respectively.
  • If quantity of any three drinks add up to X then we'll have it else we'll return the order.
    E.g. If a + d + f = X then True else False
You are given
  1. Number of bottles N corresponding to different beverages and hence their sizes
  2. Next N lines, contain a positive integer corresponding to the size of the beverage
  3. Last line consists of an integer value, denoted by X above
Your task is to help find out if there can be any combination of three beverage sizes that can sum up to the quantity they intend to consume. If such a combination is possible print True else False
Input Format: 
  1. First line contains number of bottles ordered denoted by N
  2. Next N lines, contains a positive integer Ai, the size of the ith bottle
  3. Last line contains the quantity they intend to consume denoted by X in text above
Output Format:
True, if combination is possible
False, if combination is not possible
Constraints:
N >= 3
Ai > 0 
1 <= i <= N
X > 0 
Sample Input and Output:


SNo.InputOutput
16
1
4
45
6
10
8
22

True
24
1
3
12
4
14

False

Program:

#include <stdio.h>
int main() {
int n,i,a[100],t,s,sum=0,f,j;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&s);
for(i=0;i<n;i++)
{
    for(j=i;j<=n;j++)
        {
          if(a[i]<a[j])
          {
              t=a[i];
              a[i]=a[j];
              a[j]=t;
          }
        }   
}
    for(i=0;i<n;i++)
    {
        sum=sum+a[i];
        if(sum==s)
        {
            printf("True");
            f=1;
            goto x;
        }
        else 
        {
            if(sum>s)
            sum=sum-a[i];
        }
    }
    if(f==0)
    printf("False");
    x:  return 0;  
    }

Output:

6
1
4
45
6
10
8
22
True

4
1
3
12
4
14
False

You can also run it on online IDE: https://ide.geeksforgeeks.org/hsuixPLs8U
Your feedback are most Welcomed! If you have any doubts you can contact me or leave it in the comment!! Cheers!!!

Related Links: Collecting Candies

TestVita | Code Vita 2015 | round 2

TestVita

Problem:

TCS is working on a new project called "TestVita". There are N modules in the project. Each module (i) has completion time denoted in number of hours (Hi) and may depend on other modules. If Module x depends on Module y then one needs to complete y before x.

As Project manager, you are asked to deliver the project as early as possible.
Provide an estimation of amount of time required to complete the project.
Input Format:

First line contains T, number of test cases.

For each test case: 
  1. First line contains N, number of modules.
  2. Next N lines, each contain:
    • (i) Module ID
    • (Hi) Number of hours it takes to complete the module
    • (D) Set of module ids that i depends on - integers delimited by space.

Output Format:

Output the minimum number of hours required to deliver the project.

Constraints:

1. 1 <= T <= 10
2. 0 < N < 1000; number of modules
3. 0 < i <= N; module ID 
4. 0 < Hi < 60; number of hours it takes to complete the module i
5. 0 <= |D| < N; number of dependencies
6. 0 < Dk <= N; module ID of dependencies

Sample Input and Output

SNo.InputOutput
1
1
5
1 5 0
2 6 1
3 3 2
4 2 3
5 1 3

16

Program:

#include <stdio.h>
int main() {
int n,m[10],t[10],d[10],q,a,i,sum=0;
scanf("%d",&a);
for(q=1;q<=a;q++)
{
scanf("%d",&n);
for(i=0;i<n;i++)
    scanf("%d %d %d",&m[i],&t[i],&d[i]);
    for(i=0;i<n-1;i++)
    {
            if(d[i]==d[i+1])
            {
                if(t[i]<t[i+1])
                t[i]=0;
                else
                t[i+1]=0;
            }
    }
   for(i=0;i<n;i++)
   {
       sum=sum+t[i];
   }
    printf("%d",sum);
}
return 0;
}

Output:

1
5
1 5 0
2 6 1
3 3 2
4 2 3
5 1 3

16

You can also run it on an online IDEhttps://ide.geeksforgeeks.org/eTqOGzjCr5

Your feedback are welcomed! If you have any doubts you can contact me or comment below! Cheers!

 Related Link: Bank Compare

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...