您的位置:首页 > 其它

AOJ-AHU-OJ-87 (HDU-2289)Cup

2014-03-30 21:07 357 查看
Cup

Time Limit: 1000 ms   Case Time Limit: 1000 ms   Memory Limit: 64 MB

Description

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.

Input

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.

Output

For each test case, output the height of hot water on a single line. Please round it to six fractional digits.

Sample Input
OriginalTransformed
1
100 100 100 3141562


Sample Output
OriginalTransformed
99.999024


Source

The 4th Baidu Cup Central China Invitational Programming Contest (Final Round)

[align=center]————————————————————归来的分割线————————————————————[/align]
[align=center]思路:坑死算了。数学题,什么定积分??不会啊!查到了一份大牛代码,直接简单的二分答案,然后根据水的高利用相似三角形求出水面半径,根据水面半径求出水的体积,看看和V是否相等即可。浮点数的二分。如此而已。直接利用圆台体积公式:[/align]
[align=center]
V = PI * H * (R*R + R*r + r*r) / 3
用杯子的体积比上水的体积得到[/align]
[align=center] H * (R2*R2 + R2*R1 + R1*R1)         Vc[/align]
[align=center]——————————————  =  ——[/align]
[align=center]h * (Rw*Rw + Rw*R1 + R1*R1)        Vw[/align]
[align=center] Rw - R1      h[/align]
[align=center]———— = —[/align]
[align=center] R2 - R1      H[/align]
[align=center]代码如下:[/align]
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
const double PI = acos(-1.0);//这个是PI的准确写法
const double eps = 1e-7;//一个精度之外的值
double v, H, R1, R2;
bool check(double m) {
double u = m/H * (R2-R1) + R1;//通过相似三角形求水面半径
double vv = PI/3 * (R1*R1 + R1*u + u*u) * m;//代入体积公式求得水的体积
if(vv > v)  return true;
return false;
}
int main() {
int cas;
scanf("%d", &cas);
while(cas--) {
scanf("%lf%lf%lf%lf", &R1, &R2, &H, &v);
double l = 0, r = 100, mid, u, vv;
while(r - l > eps) {
mid = (l+r) * 0.5;
if(check(mid))  r = mid;
else            l = mid;
}
printf("%.6f\n", mid);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: