ACM HDU 3668Volume

Volume

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 531    Accepted Submission(s): 159


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<stdio.h>
#include
<iostream>
#include
<cmath>
using namespace std;

#define PI acos(-1.0)

int main()
{
double r,h;
double v;
while(cin>>r>>h)
{
if(h>=2*r)
v
=2*PI*r*r*h-16*r*r*r/3;
else
v
=2*PI*r*r*h-8*r*r*(r-sqrt(r*r-h*h/4))+8*(r*r*r-sqrt((r*r-h*h/4)*(r*r-h*h/4)*(r*r-h*h/4)))/3-8*h*h*sqrt(r*r-h*h/4)/4;
printf(
"%.4lf\n",v);
}
return 0;
}

posted on 2011-07-28 17:43  kuangbin  阅读(350)  评论(0编辑  收藏  举报

导航

JAVASCRIPT: