Volume
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 214 Accepted Submission(s): 68
Problem Description
This time your job is to calculate the volume of a special object. The object consists of two orthogonal cylinders. The two cylinders intersect each other in the middle place. One example is shown in Fig. 1. The radiuses of the bottom disk of both cylinders are R, and the heights of both cylinders are H.
Input
We test the problem in many cases. Each case includes two integers, the first one is R and the second one is H. All the numbers given are positive integers and are less than 100.
Output
The output consists of the volumes. The results must be round to 4 decimal numbers. Remember that R may be less than half of H.
Sample Input
10 30 10 40
Sample Output
13516.2226 19799.4079
Source
Recommend
lcy
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double pi=acos(-1.0);
int main()
{
int r,h;
while(scanf("%d%d",&r,&h)==2)
{
double v=pi*r*r*h;
double t;
if(r*2<h) t=16.0/3*r*r*r;
else
{
double k=1.0*h/2;
double x0=sqrt(0.0+r*r-k*k);
double s1,s2;
// cout<<"r="<<r<<"...."<<"k="<<k<<"..."<<"x0="<<x0<<endl;
s1=(r*r*r-r*r*x0-1.0/3*r*r*r+1.0/3*x0*x0*x0);
//s2=k*(r*r*1.0/2*asin(x0*1.0/r)+1.0/2*x0*sqrt(r*r-x0*x0+0.0));
s2=k*k*x0;
t=(s1+s2)*8;
//cout<<"s1="<<s1<<"..."<<"s2="<<s2<<endl;
}
double cnt=2*v-t;
//cout<<"v="<<v<<"...."<<2*v<<"..."<<"t="<<t<<endl;
printf("%.4lf/n",cnt);
}
return 0;
}
#include<cstdio>
#include<cmath>
using namespace std;
const double pi=acos(-1.0);
int main()
{
int r,h;
while(scanf("%d%d",&r,&h)==2)
{
double v=pi*r*r*h;
double t;
if(r*2<h) t=16.0/3*r*r*r;
else
{
double k=1.0*h/2;
double x0=sqrt(0.0+r*r-k*k);
double s1,s2;
// cout<<"r="<<r<<"...."<<"k="<<k<<"..."<<"x0="<<x0<<endl;
s1=(r*r*r-r*r*x0-1.0/3*r*r*r+1.0/3*x0*x0*x0);
//s2=k*(r*r*1.0/2*asin(x0*1.0/r)+1.0/2*x0*sqrt(r*r-x0*x0+0.0));
s2=k*k*x0;
t=(s1+s2)*8;
//cout<<"s1="<<s1<<"..."<<"s2="<<s2<<endl;
}
double cnt=2*v-t;
//cout<<"v="<<v<<"...."<<2*v<<"..."<<"t="<<t<<endl;
printf("%.4lf/n",cnt);
}
return 0;
}
本文介绍了一种特殊的几何体——两个正交圆柱体相交的体积计算方法。该几何体由两个圆柱体组成,它们在中间位置相交。文章提供了一个C++程序示例,用于计算不同半径和高度的此类几何体体积。
1101

被折叠的 条评论
为什么被折叠?



