HDU2289

来源:互联网 发布:知乎 闲书 编辑:程序博客网 时间:2024/06/05 09:21
C -Cup
Crawling in process...Crawling failedTime Limit:1000MS    Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
SubmitStatus Practice HDU 2289 uDebug

Description

Input

Output

Sample Input

Sample Output

Hint

Description

一个杯子装了很多水,可以把杯子看成圆台,并给出圆台的底面半径,顶部半径,高还有水的体积,求水的高度。

Input

输入包括T组数据
每组数据包含一行,并且有四个数r, R, H, V代表圆台底部半径,顶部半径,高度和水的体积。

1. T ≤ 20.
2. 1 ≤ r, R, H ≤ 100; 0 ≤ V ≤ 1000,000,000.
3. r ≤ R.
4. r, R, H, V 输入
5. 无空数据

Output

答案为一行,保留6位小数

Sample Input

1100 100 100 3141562 

Sample Output

99.999024 
数学题,WA了几发,再次提醒,结果要求什么,就最好用其进行二分,
不然会卡在精度上。。。
#include<iostream>#include<cstdio>#include<cmath>using namespace std;#define PI acos(-1.0)double r,R,H,V;double a;inline double f(double h){    return(a*a/3*PI*h*h*h+PI*a*r*h*h+PI*r*r*h);}int main(){    int t;    double left,right;    double mid;    scanf("%d",&t);    while(t--)    {        scanf("%lf%lf%lf%lf",&r,&R,&H,&V);        a=(R-r)/H;        left=0;right=H;        while(right-left>1e-7)        {            mid=(left+right)/2;            if(f(mid)>V) right=mid;            else left=mid;        }        printf("%.6f\n",mid);    }    return 0;}


0 0