小记:不知道公式,用二分瞄了很久,还是没A,后来知道应该是没处理特殊情况了,
思路:二分可以,数学方法也可以
如果是圆柱直接就可以求出高
h0 = V/(π*r*r)
如果是圆锥柱,那么求出最上面没有的圆锥的体积,然后根据圆锥体积比是高的比的3倍来求出高
h = r*H/(R-r)
V0 = (PI*h*r*r)/3.0
h0 = h*(pow((V0/(V0+V),1.0/3) - 1)
(V0/(V0+V) )^(1/3)= (h+h0)/h;
如果V0 大于圆锥柱的体积V,那么就相当于h0>H,那么就只能装H,
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
#define mst(a,b) memset(a,b,sizeof(a))
#define eps 10e-10
#define PI acos(-1.0)//3.14159265
const int MAX_ = 510;
const int N = 100010;
const int INF = 0x7fffffff;
double r, R, H, V;
int main(){
int k;
double h, h0, V0;
scanf("%d",&k);
while(k--){
scanf("%lf%lf%lf%lf",&r,&R,&H,&V);
if(r == R){
h0 = V/(PI*r*r);
}
else if(r < R){
h = r*H/(R-r);
V0 = (PI*r*r*h)/3.0;
h0 = h*(pow((V0+V)/V0, 1.0/3) - 1);
}
if(h0 > H)h0 = H;
printf("%.6lf\n",h0);
}
return 0;
}