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

    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.

    InputThe 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. 

    OutputFor 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

    解题思路:
    推公式然后二分暴搜

    实现代码:
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <bitset>
    using namespace std;
    
    #define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)
    #define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)
    #define pb push_back
    #define mp make_pair
    const int inf_int = 2e9;
    const long long inf_ll = 2e18;
    #define inf_add 0x3f3f3f3f
    #define mod 1000000007
    #define LL long long
    #define ULL unsigned long long
    #define MS0(X) memset((X), 0, sizeof((X)))
    #define SelfType int
    SelfType Gcd(SelfType p,SelfType q){return q==0?p:Gcd(q,p%q);}
    SelfType Pow(SelfType p,SelfType q){SelfType ans=1;while(q){if(q&1)ans=ans*p;p=p*p;q>>=1;}return ans;}
    #define Sd(X) int (X); scanf("%d", &X)
    #define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)
    #define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
    #define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
    #define all(a) a.begin(), a.end()
    #define   mem(x,v)      memset(x,v,sizeof(x))
    typedef pair<int, int> pii;
    typedef pair<long long, long long> pll;
    typedef vector<int> vi;
    typedef vector<long long> vll;
    #define PI acos(-1.0)
    #define exp 1e-9
    double fuck(double r,double R,double h,double H)
    {
        double u = h/H*(R-r) + r;
        return PI/3*(r*r+r*u+u*u)*h;
    }
    int main()
    {
        int t;
        double r,R,H,V,mid,v,right,left;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%lf%lf%lf%lf",&r,&R,&H,&V);
            left=0;
            right=100;
            while(right-left>exp)
            {
                mid=(right+left)/2;
                v=fuck(r,R,mid,H);
                if(fabs(v-V)<=exp)
                    break;
                else if(v>V)
                    right=mid-exp;
                else
                    left=mid+exp;
            }
            printf("%.6lf
    ",mid);
        }
        return 0;
    }
  • 相关阅读:
    Spring通过springframework.data的@PageableDefault注解分页
    Specifications动态查询
    IDEA生成序列号serialVersionUID快捷键
    JS组件系列——表格组件神器:bootstrap table(还没细看)
    南昌网络赛 Distance on the tree(可持久化线段树)
    南昌网络赛 Max answer(单调栈)
    HDU 6148 Valley Numer(数位DP)
    python 二位dict
    Codeforces Round #230 (Div. 2) 题解
    Codeforces Round #228 (Div. 2) 题解
  • 原文地址:https://www.cnblogs.com/kls123/p/7132457.html
Copyright © 2011-2022 走看看