1 1 1 2 1 1
0.666667 0.187500
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<math.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=100010;
const double PI=acos(-1.0);
const double eps=1e-8;
typedef long long ll;
int main()
{
double r,hr,hz,vc,vu,d,a,b,hh;
while(~scanf("%lf%lf%lf",&r,&hr,&hz))
{
if(hr<r)
{
d=sqrt(r*r-hr*hr);
if(hz<=d)
vc=2*PI*hr*hr*hz;
else
{
hh=min(hz,r);
a=PI*r*r*hh-PI*hh*hh*hh/3;
b=PI*r*r*d-PI*d*d*d/3;
vc=2*(PI*hr*hr*d+a-b);
}
}
else
{
if(hz<=r)
vc=2*(PI*r*r*hz-PI*hz*hz*hz/3);
else
vc=4*PI*r*r*r/3;
}
vu=4*PI*r*r*r/3+PI*hr*hr*hz*2-vc;
//printf("%lf %lf\n",vc,vu);
printf("%.6lf\n",vc/vu);
}
return 0;
}
原文:http://blog.csdn.net/bossup/article/details/39812625