hdu-2289-Cup
来源:互联网 发布:圆形进度条js代码 编辑:程序博客网 时间:2024/06/05 04:20
经典二分
点击打开链接看原题
Problem 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.
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.
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
1100 100 100 3141562
Sample Output
99.999024代码#include <cstdio>#include <iostream>#include <cmath>#include <cstring>#include <cstdlib>#include <string>#include <queue>#include <vector>#include <stack>#include <algorithm>#define esp 1.0e-10#define PI acos(-1.0)using namespace std;int T;double r,R,H,V,ri,l,mid;double Vo(double x){ double u=(R-r)*x/H+r; return (pow(r,2)+pow(u,2)+r*u)/3*PI*x;}int main (){ while ( scanf ("%d",&T)!=EOF) { while (T--) { scanf ("%lf %lf %lf %lf",&r,&R,&H,&V); double l=0,ri=R; if(V==0) { printf ("%.6lf\n",0); continue; } while(ri-l>esp) { mid=(l+ri)/2; if(Vo(mid)>V) ri=mid; else l=mid; } printf("%.6lf\n",(l+ri)/2); } } return 0;}
方法:
这里就是先确定圆台的体积公式V=1/3πH(R^2+r^2+R*r);我居然还可以用微积分求出这个公式,尴尬啊。
然后就是找到H和r的一个关系式,利用相似三角形。
0 0
- HDU 2289 Cup
- hdu 2289 CUP
- hdu 2289 cup
- hdu 2289 Cup
- hdu 2289 Cup (二分法)
- HDU 2289 Cup
- HDU 2289 Cup(二分)
- HDU 2289 Cup.
- HDU 2289 Cup 二分
- hdu 2289 Cup(二分)
- HDU 2289 cup
- HDU 2289 Cup
- HDU-2289 Cup
- HDU 2289 Cup
- HDU - 2289 CUP
- HDU 2289 Cup
- hdu 2289 Cup
- hdu-2289-Cup
- 二进制与逻辑运算
- 利用”异或”运算的性质,对几个字符进行加密并输出密文,然后再解密。加密算法是:密钥是字符’8’,明文的每个字符和密钥进行异或运算,得到密文。密钥和密文的每个字符再次进行异或运算,重新得到明文。
- 【UVA 11624】Fire!(BFS)
- poj 1611 The Suspects
- linux命令
- hdu-2289-Cup
- 02-android之NDK hellojni实例
- #6.Linux的进程管理
- HDU 4496 D-City(逆向)
- 图论 C - 最短路
- leetcode 69 sqrt(x)
- Caffe-Windows下遇到过的问题、技巧、解决方案
- leetcode Course Schedule
- windows安装TortoiseGit详细使用教程【基础篇】