zoukankan      html  css  js  c++  java
  • hdoj 2289 Cup

    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
     
     
     1     #include <cstdio>
     2     #include <cmath>
     3     #define pi acos(-1.0)//圆周率
     4     #define exp 1e-9 //精度
     5 
     6     double  gets(double h, double H, double r, double R)
     7     {
     8         double k = h / H * (R - r) + r; //根据三角形的相识原理求出当前高度的上底的圆的半径;
     9         return pi / 3.0 *(r * r + r * k + k * k) * h;//圆台的体积等于三分之一高乘于上底和下底的面积在加上上底和下底的乘积的开方;
    10     }
    11 
    12     int main()
    13     {
    14        int T;
    15        double r,R,h,H,V;
    16        scanf("%d",&T);
    17        while(T--)
    18        {
    19            scanf("%lf %lf %lf %lf",&r,&R,&H,&V);
    20            double ua,ub;
    21            ua = 0;
    22            ub = H;
    23            while(ua < ub)
    24            {
    25                h = (ua + ub) / 2.0;
    26                double sum = gets(h,H,r,R);
    27         if(sum < V) ua = h + exp;//当前的水体积小于原本的体积,则高度不够,缩小区间
    28                else ub = h - exp;
    29            }
    30            printf("%.6lf
    ",ua);
    31        }
    32        return 0;
    33     }
  • 相关阅读:
    手贱!使用django,在数据库直接删除了表
    js中在一个函数中引用另一个函数中的函数,可以这么做
    上传下载文件方式
    阻止form提交数据,通过ajax等上传数据
    一种思路,隐藏input标签,通过label关联
    java 寻找水仙花数
    java 统计素数个数问题
    java 兔子生仔问题
    java 实现读取某个目录下指定类型的文件
    通过java 来实现对多个文件的内容合并到一个文件中
  • 原文地址:https://www.cnblogs.com/z-712/p/7323731.html
Copyright © 2011-2022 走看看