Cup HDU 2289

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

 1 #include <stdio.h>
 2 #include <math.h>
 3
 4 const double Pi=acos(-1.0);
 5 double h0;
 6
 7 double VV(double r,double R,double H)
 8 {
 9     return Pi*H*(R*R+r*r+R*r)/3.0;
10 }
11
12 bool C(double r,double h,double V)
13 {
14     double R=r*(h0+h)/h0;
15     double v=Pi*h*(R*R+r*r+R*r)/3.0;
16     if(v<=V)
17         return true;
18     else
19         return false;
20 }
21
22 bool C2(double r,double h,double V)
23 {
24     double v=r*r*Pi*h;
25     if(v<=V)
26         return true;
27     else
28         return false;
29 }
30
31 int main()
32 {
33     int T;
34     scanf("%d",&T);
35     while(T--)
36     {
37         double r,R,H,V;
38         scanf("%lf %lf %lf %lf",&r,&R,&H,&V);
39         if(VV(r,R,H)<=V)
40             printf("%.6lf\n",H);
41         else
42         {
43             double lb=0,ub=H;
44             if(R!=r)
45             {
46                 h0=r*H/(R-r);
47                 for(int i=1;i<=100;i++)
48                 {
49                     double mid=(lb+ub)/2.0;
50                     if(C(r,mid,V))
51                         lb=mid;
52                     else
53                         ub=mid;
54                 }
55                 printf("%.6lf\n",lb);
56             }
57             else
58             {
59                 for(int i=1;i<=100;i++)
60                 {
61                     double mid=(lb+ub)/2.0;
62                     if(C2(r,mid,V))
63                         lb=mid;
64                     else
65                         ub=mid;
66                 }
67                 printf("%.6lf\n",lb);
68             }
69
70         }
71     }
72     return 0;
73 }

时间: 2024-10-11 03:27:10

Cup HDU 2289的相关文章

HDU 2289 Cup(二分可以,但是除了二分呢?)

这道题目,算数学题吗?算二分题吗?充其量算个水题吧... 首先,没有用二分,但是发现了一种新的解法来代替二分. 若果按照i从0,每次增加0.00000001来一直枚举到h的话,绝逼超时.枚举量太大了 但是可以分成两步来呀: #include<cstdio> #include<cmath> #define pai acos(-1.0) double r1,r2,h,v; double get_v(double temp) { double rr=r1+(r2-r1)*temp/h;

HDU 2289 Cup【高精度,二分】

Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8942    Accepted Submission(s): 2744 Problem Description The WHU ACM Team has a big cup, with which every member drinks water. Now, we know th

HDU 2289 Cup

Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5597    Accepted Submission(s): 1787 Problem Description The WHU ACM Team has a big cup, with which every member drinks water. Now, we know th

HDU 2289 Cup【二分】

<题目链接> 题目大意: 一个圆台型的杯子,它的上底半径和下底半径已经给出,并且给出它的高度,问你,体积为V的水倒入这个杯子中,高度为多少. 解题分析: 就是简单的二分答案,二分枚举杯中水的高度,然后根据几何计算出该高度下,水的上半径,然后计算出该高度下水的体积,在与实际水的体积进行比较,从而确定最终的答案. 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 5 const doubl

【HDOJ】2289 Cup

二分.另外,圆台体积为v = PI*(r*r+r*R+R*R)*H/3.注意精度. 1 #include <cstdio> 2 #include <cmath> 3 4 #define exp 1e-9 5 6 const double PI = acos(-1.0); 7 8 int main() { 9 int t; 10 double r, R, H, v, lf, rt, mid, r0, nv; 11 scanf("%d", &t); 12 1

HDU 5999: The Third Cup is Free

///@link http://acm.hdu.edu.cn/showproblem.php?pid=5999///@author Sycamore///@date Aug, 16#include<bits/stdc++.h>using namespace std;int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin>>T; for(int t=1;t<=T;t++) { int n; cin>&

hdu Cup

这题是道水题,用数学方法做比较简单.因为在做二分法的专题,所以这里采用二分的方式做,很简单,但是还是要用到数学的知识,比如三角形相似,圆台的 体积公式等. #include"iostream" #include"stdio.h" #include"algorithm" #include"string.h" #include"cmath" #define inf 1e-9 using namespace st

Cup(二分)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2289 hdu_2289:Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5747    Accepted Submission(s): 1807 Problem Description The WHU ACM Team has a b

hud 2289 要二分的杯子

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2289 大意是 一个Cup,圆台形,给你它的顶部圆的半径,底部圆的半径,杯子的高度,和此时里面装的水的体积,求水的高度. 这道题好在能够锻炼算法思维,或者说形成算法思维. 这是一道二分逼近求值的应用 题目已经给定杯子的高度是0~100,故在这个范围内进行二分,但走了涉及到还有小数的问题,故可以取一个精度较高的误差值 来作为二分的条件,二分一次,以这个值作为水的高度求出水的体积与实际值比较一次,当误差不