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     }
  • 相关阅读:
    配置别名
    Git永久删除commit--[非教程]
    忽略特殊文件
    自定义Git
    使用GitHub
    模块化开发的几种思想AMD,CMD,commonJS,es6
    angualr设置select默认值
    在vue-cli中引入jquery的坑
    chromedriver@2.33.2 install: `node install.js` vue脚手架安装报错
    vue事件绑定demo
  • 原文地址:https://www.cnblogs.com/z-712/p/7323731.html
Copyright © 2011-2022 走看看