HDU 2289 Cup 数学+二分

发布时间:2016-12-10 16:45:54 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"HDU 2289 Cup 数学+二分",主要涉及到HDU 2289 Cup 数学+二分方面的内容,对于HDU 2289 Cup 数学+二分感兴趣的同学可以参考一下。

这道题的题意是:给你一个杯子,然后告诉你杯子的下顶面的半径,上顶面的半径,杯子总的高度,还有就是杯子中水的体积。(这里水的体积竟然可以比杯子还大啊!),然后输出现在杯中水的高度。 注意这里的模型是一个圆台。圆台的面积公式是V = PI*(r1*r1+r1*r2+r2*r2)*h/3。 主要是想到要把圆台补成圆锥,然后用相似三角形找到高度比与半径比的关系,之后可以用数学方法推算出比例,然后求出高度h',也可以用二分枚举高度。注意二分的精度要小于10^(-7)。 Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3085    Accepted Submission(s): 964 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.   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 1 100 100 100 3141562   Sample Output 99.999024   Source The 4th Baidu Cup final 二分算法: #include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include <iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include <stack> #include <map> #include <set> #define eps 1e-7 #define M 1000100 //#define LL __int64 #define LL long long #define INF 0x3f3f3f3f #define PI 3.1415926535898 const int maxn = 250100; using namespace std; int main() { int n; cin >>n; while(n--) { double r1, r2, h, v; cin >>r1>>r2>>h>>v; if(PI*(r1*r1+r1*r2+r2*r2)*h/3 < v) { printf("%.6lf\n",h); continue; } if(r1 == r2) { printf("%.6lf\n",v/(PI*r1*r1)); continue; } double hh = r1*h/(r2-r1); double l = 0.0, r = h; double mid; while(r-l > eps) { mid = (r+l)/2; double h1 = mid+hh; double x = mid*(r2-r1)/h; double vv = ((r1+x)*(r1+x)*h1-r1*r1*hh)*PI/3.0; if(v > vv) l = mid; if(v < vv) r = mid; } printf("%.6lf\n",mid); } return 0; } 数学做法: #include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include <iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include <stack> #include <map> #include <set> #define eps 1e-7 #define M 1000100 #define LL __int64 #define INF 0x3f3f3f3f #define PI 3.1415926535898 const int maxn = 250100; using namespace std; int main() { double r1, r2, h, v; int n; cin >>n; while(n--) { cin >>r1>>r2>>h>>v; double v1 = PI*(r1*r1+r2*r2+r1*r2)*h/3.0; if(v > v1) { printf("%.6lf\n",h); continue; } if(r1 == r2) { double H; H = v/(PI*r1*r1); printf("%.6lf\n",H); continue; } double hh=(r1*h)/(r2-r1); double H = hh+h; double vv = PI*r1*r1*hh/3.0; double V = PI*r2*r2*H/3.0; printf("%.6lf\n",pow((vv+v)/V,1.0/3)*H-hh); } return 0; }

上一篇:android ListView几个比较特征的属性
下一篇:DRBD安装测试过程记录(二)

相关文章

相关评论