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; }
相关文章推荐
- HDU2289_Cup_二分求圆台体积
- HDU 2289(二分法 圆台体积)
- 圆台体积公式的推导
- hdu 2285 Cup(二分,求圆台的体积)
- HDU2289(二分法)
- HDU 2289 Cup(二分+圆台体积)
- 1441. Pie(二分法求可以分得Pie的最大体积)
- 第三周—二分法4 已知面积,求最大体积
- zoj 1904 Beavergnaw 计算圆柱和圆台的体积
- 二分法(折半法)查找数据的一个简单例子
- Constructing Roads In JGShining's Kingdom----HDU_1025----用二分法求最长单调子序列
- 二分法 排序
- POJ 3642 长方体体积并 线段树 扫描线
- 二分法查找算法 (递归)
- 修路 hrbust (二分法)
- hdu3255 线段树体积并
- HDU3756二分或三分求满足题意的圆锥体积
- 第2章:计算机圆柱体的体积
- 二分法常用模板
- hdu2002――计算球体积