You have to know about Volume of frustum of a cone . We will discuss a little bit about this . Hope after that you will get a complete idea about this
A frustum (unfortunately commonly misspelled "frustrum") is that portion of a solid which lies between two parallel planes cutting the solid. Degenerate cases are obtained for finite solids by cutting with a single plane only.
A frustum may be formed from a cone with a circular base by cutting off the tip of the cone with a cut perpendicular to the height, forming a lower base and an upper base that are circular and parallel.
Let h be the height, R the radius of the lower base, and r the radius of the upper base. One picture of the frustum is the following.
The main problem is "Given R, r, and h, find the volume of the frustum. " The formula is ,
Now lets come back to the main problem of light online judge :
It is slightly a different version of our discussion . As we have to find the volume of only coloured space of the glass , the formula is as following :
If R1 = r1 .
R2 = r2 + (r1-r2)*p/h
H=p
The the volume of colured glass is V = 1/3 * H * ( R1*R1 + R2*R1 + R2*R2 )
Hope after this discussion all things are very much clearer to you . Have a great day .
Code :
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
#define PI acos(-1)
int main()
{
int i,test,r1,r2,h,p;
double R,V;
cin>>test;
for(i=1;i<=test;i++)
{
cin>>r1>>r2>>h>>p;
R= r2 + (r1-r2)*(double(p)/h);
V = 1/3.0 * PI * p *( R*R + R*r2 + r2*r2 );
printf("Case %d: %lf\n",i,V);
}
return 0;
}
the way you got the radius is not clear to me
উত্তরমুছুনNot clear for radius
উত্তরমুছুনcorrection: R1=r2, the code says so.
উত্তরমুছুনWhat do you want to mean by this ?
মুছুনHow R2 = r2 + (r1-r2)*p/h??
উত্তরমুছুনso ,at first we get radius of bottom ,but how get radius of top portion of juice,
this will be r2+increased value.
so how get the increased value
Let
for h radius increased (r1-r2)
1 ,, ,, (r1-r2)/h
p ,, ,, p*(r1-r2)/h
so, thats way we get the increased value of radius..
thannks vai
উত্তরমুছুন