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?
![](http://icpc.ahu.edu.cn/OJ/images/1086.jpg)
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
Sample Output
Source
The 4th Baidu Cup Central China Invitational Programming Contest (Final Round)
[align=center]————————————————————归来的分割线————————————————————[/align]
[align=center]思路:坑死算了。数学题,什么定积分??不会啊!查到了一份大牛代码,直接简单的二分答案,然后根据水的高利用相似三角形求出水面半径,根据水面半径求出水的体积,看看和V是否相等即可。浮点数的二分。如此而已。直接利用圆台体积公式:[/align]
[align=center]
[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]
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?
![](http://icpc.ahu.edu.cn/OJ/images/1086.jpg)
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
Original | Transformed |
1 100 100 100 3141562
Sample Output
Original | Transformed |
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; }
相关文章推荐
- HDU_2289_Cup
- HDU 2289 Cup 数学+二分
- AOJ-AHU-OJ-394 Fibonacci numbers
- AOJ-AHU-OJ-489 夺宝奇兵
- HDU 2289 Cup(二分可以,但是除了二分呢?)
- AOJ-AHU-OJ-13(POJ-1056) IMMEDIATE DECODABILITY
- hdu 2289 Cup(数学题)
- hdu-2289-Cup
- AOJ-AHU-OJ-401 Fibonacci & GCD
- AOJ-AHU-OJ-34 Euchre Results
- hdu 2289 Cup (二分)
- AOJ-AHU-OJ-460 Prime Ring Problem(巩固)
- AOJ-AHU-OJ-351 求最值之差
- AOJ-AHU-OJ-595 撒哈拉大冒险(栈)
- day5 HDU 2289 Cup
- AOJ-AHU-OJ-298 Rings of square grid
- AOJ-AHU-OJ-6 Hero in Maze
- HDU 2289 Cup(二分+圆台体积)
- AOJ-AHU-OJ-11 Rails
- AOJ-AHU-OJ-145 流水线作业调度问题