zoukankan      html  css  js  c++  java
  • Cup

    Cup

    http://acm.hdu.edu.cn/showproblem.php?pid=2289

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 11638    Accepted Submission(s): 3556


    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

    H变化的话,R也会变。。。一开始没考虑清楚,WA的几发

     1 #include<iostream>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<cmath>
     5 #include<string>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<stack>
    10 #define PI acos(-1.0)
    11 #define eps 1e-9
    12 using namespace std;
    13 double r,R,H,V;
    14 bool Check(double mid){
    15     double rr = mid/H*(R-r) + r;
    16     double tmp=1.0/3*PI*mid*(r*r+rr*rr+r*rr);
    17     if(tmp-V>eps) return true;
    18     return false;
    19 }
    20 
    21 int main(){
    22     int T;
    23     scanf("%d",&T);
    24     while(T--){
    25         
    26         scanf("%lf %lf %lf %lf",&r,&R,&H,&V);
    27         double tmp=1.0/3*PI*H*(r*r+R*R+r*R);
    28         if(V-tmp>eps){
    29             printf("%.6f
    ",H);
    30         }
    31         else{
    32             double L=0,R=H;
    33             double mid;
    34             while(R-L>eps){
    35                 mid=(L+R)/2;
    36                 if(Check(mid)){
    37                     R=mid;
    38                 }
    39                 else{
    40                     L=mid;
    41                 }
    42             }
    43             mid=round(mid*1e6)/1e6;
    44             printf("%.6f
    ",mid);
    45         }
    46     }
    47     system("pause");
    48 }
    View Code
  • 相关阅读:
    为什么说LD_LIBRARY_PATH不好
    linux c/c++ code统计耗时
    c++: abs() 与fabs() 的区别
    char代表有符号还是无符号?
    git三个小技巧:删除指定 commit、修改历史 commit 中的作者信息、合并某文件到当前分支
    vim选中字符复制/剪切/粘贴
    git rebase
    git打patch
    数据仓库生命周期工作箱 第六章 维度建模
    数据仓库生命周期工作箱 第二章 项目/项目群的启动与管理
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/10040460.html
Copyright © 2011-2022 走看看