zoukankan      html  css  js  c++  java
  • E

    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

    给你水杯的下上半径和高,在给你水的体积,求水高,二分一下就行,注意圆台的公式V=(1/3.0)πh(RR+rr+rR)

    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include <iomanip>
    #include<cmath>
    #include<float.h> 
    #include<string.h>
    #include<algorithm>
    #define sf scanf
    #define pf printf
    #define pb push_back
    #define mm(x,b) memset((x),(b),sizeof(x))
    #include<vector>
    #include<map>
    #define for(i,a,b) for(int i=a;i<b;i++)
    typedef long long ll;
    typedef long double ld;
    typedef double db;
    const ll mod=1e12+100;
    const db e=exp(1);
    using namespace std;
    const double pi=acos(-1.0);
    db V,r,R,H;
    int judge(db mid)
    {
    	db rr=(R-r)*mid/H+r;
    	db v=(1/3.0)*pi*mid*(rr*rr+r*r+rr*r);
    	if(v==V) return 0;
    	if(v>V) return 1;
    	return -1;
    }
    int main()
    {
    	int re;
    	cin>>re;
    	while(re--)
    	{
    		sf("%lf%lf%lf%lf",&r,&R,&H,&V);
    		db right=H,left=0,mid;
    		while(right-left>0.00000001)
    		{
    			mid=(left+right)/2;
    			if(judge(mid)==0)
    			 break;
    			else if(judge(mid)>0)
    			 right=mid;
    			else 
    			left=mid;
    		}
    		pf("%.6lf
    ",mid);
    	}
    	return 0;
    }
    
  • 相关阅读:
    “校园知网”5月11日冲刺计划书
    “校园知网”5月10日冲刺计划书
    “校园知网”5月9日冲刺计划书
    学习进度
    “校园知网”5月8日冲刺计划书
    “校园知网”5月7日冲刺计划书
    “校园知网”5月6日冲刺计划书
    “校园知网”5月5日冲刺计划书
    “校园知网”5月4日冲刺计划书
    04-课后作业2-动手动脑及String类整理
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9382381.html
Copyright © 2011-2022 走看看