您的位置:首页 > 其它

HDU2289 二分

2016-02-23 15:18 381 查看
π的精度高一点,然后在注意一下半径就可以了。

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

const double pai = 3.1415926535898;
double r, R, h, v;

double cal(double r, double R, double h){
double res = pai * h * (R * R + r * r + R * r) / 3.0;
return res;
}

void solve(){
double lb = 0, ub = h;
for (int i = 0; i < 100; i++){
double mid = (lb + ub) / 2;
double midv = cal(r, r+(R-r)*mid/h, mid);
if (midv >= v){ub = mid;}
else lb = mid;
}
printf("%.6f\n", lb);
}

int main(){
int t;
scanf("%d", &t);
while (t--){
scanf("%lf%lf%lf%lf", &r, &R, &h, &v);
solve();
}
return 0;
}
</cstring></algorithm></cstdio>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: