您的位置:首页 > 编程语言 > PHP开发

hdu2289 二分法 圆台体积

2012-08-16 19:52 148 查看

Cup

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1616    Accepted Submission(s): 509


[align=left]Problem Description[/align]
The WHU ACM Team has a big cup, with which every member drinks water. Now, we know the volume of the water in the cup, can you tell us it height?

The radius of the cup's top and bottom circle is known, the cup's height is also known.
 

 

[align=left]Input[/align]
The input consists of several test cases. The first line of input contains an integer T, indicating the num of test cases.

Each test case is on a single line, and it consists of four floating point numbers: r, R, H, V, representing the bottom radius, the top radius, the height and the volume of the hot water.

Technical Specification

1. T ≤ 20.

2. 1 ≤ r, R, H ≤ 100; 0 ≤ V ≤ 1000,000,000.

3. r ≤ R.

4. r, R, H, V are separated by ONE whitespace.

5. There is NO empty line between two neighboring cases.

 

 

[align=left]Output[/align]
For each test case, output the height of hot water on a single line. Please round it to six fractional digits.
 

 

[align=left]Sample Input[/align]

1100 100 100 3141562

 

 

[align=left]Sample Output[/align]

99.999024

 

题意:

        给定一个圆台的上底半径,下底半径和高,给出一定体积的水,求这些水在圆台内的体积。

        简单的二分法逼近求高,

题目大意:输入一个正整数t,表示有t个测试数据,每组测试数据输入四个双精度数,分别表示杯子的底半径,杯口半径(底半径《=杯口半径),杯子高,还有要装的水的体积,求水装进杯子有多高。

这题要注意的是当水高大于杯子的高时,水的高应该等于杯子的高。

/*r, R, H, V, representing
the bottom radius, the top radius, the height and the volume of the hot water.
这句话是重点  of the hot water. 仅仅是指 the volume
*/
#include<stdio.h>
#include<math.h>
double R,r,H,v,PI;
double find(double high)
{
double ans,R2; //水面的半径依然要求
R2=(high/H)*(R-r)+r;
return ans=(1.0/3.0)*PI*high*(r*r+R2*R2+R2*r);
}
int main()
{
int cas;
double start,end,mid,temp;
scanf("%d",&cas);
PI=acos(-1.0);//重啊!!!  精确度很重要
while(cas--)
{
scanf("%lf %lf %lf %lf",&r,&R,&H,&v);//妈的 木有看懂题意啊  原来rRh都是杯子的 v才是水的 哎 英语不好啊
start=0;end=100;//题目测试数据有问题 测试从0开始 但是题目表明的是从1到100啊
while(end-start>0.0000000001)
{
mid=(end+start)/2;
temp=find(mid);
if(temp<v)  start=mid;
if(temp>v)  end=mid;
}
printf("%.6lf\n",(end+start)/2);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息