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
  • 相关阅读:
    iOS 文件操作--归档和解档
    iOS中UITabBarController的使用
    Objective-C基础知识点总结,字符串操作,数组操作,字典操作
    Objective-C中协议和分类总结
    Objective-C文件操作之NSCoding协议之小练习
    浅谈Objective-C继承和多态
    Objective-C内存管理基础知识
    MySort(选做)的实现
    20175308 2018-2019-2 实验四 《Android开发基础》实验报告
    JAVA 第十一周学习总结
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/10040460.html
Copyright © 2011-2022 走看看