HDU2289——二分——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.

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

/*
耐心点推个公式
精度!!!。。。
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

const double esp = 1e-9;
const double pi = acos(-1.0);
int T;
double r, R, H, V;
double check(double x)
{
    double rr = x/H*(R-r) + r;
   // printf("%f\n",rr);
    double V1 = pi/3*x*(rr*rr + r*r + rr*r);
    return V1;
}

int main()
{
    scanf("%d", &T);
    while(T--){
        scanf("%lf%lf%lf%lf", &r, &R, &H, &V);
      //  if(r == R) {
      //     printf("%.6f\n", V/(pi*r*r));
      //     continue;
      //
        double ll = 0, rr = 100, mid;
        while(rr - ll  > esp){
         mid = (ll + rr) / 2;
        double VV = check(mid);
        if(fabs(VV - V) <= esp)
            break;
        else if(VV > V)
            rr = mid - esp;
        else ll = mid + esp;
        }
     printf("%.6f\n", mid);
    }
    return 0;
}

  

时间: 2024-11-07 05:31:25

HDU2289——二分——Cup的相关文章

Cup(二分)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2289 hdu_2289:Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5747    Accepted Submission(s): 1807 Problem Description The WHU ACM Team has a b

HDU 2289 Cup(二分可以,但是除了二分呢?)

这道题目,算数学题吗?算二分题吗?充其量算个水题吧... 首先,没有用二分,但是发现了一种新的解法来代替二分. 若果按照i从0,每次增加0.00000001来一直枚举到h的话,绝逼超时.枚举量太大了 但是可以分成两步来呀: #include<cstdio> #include<cmath> #define pai acos(-1.0) double r1,r2,h,v; double get_v(double temp) { double rr=r1+(r2-r1)*temp/h;

HDU 2289 Cup【高精度,二分】

Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8942    Accepted Submission(s): 2744 Problem Description The WHU ACM Team has a big cup, with which every member drinks water. Now, we know th

【二分】【字符串哈希】【二分图最大匹配】【最大流】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem I. Minimum Prefix

给你n个字符串,问你最小的长度的前缀,使得每个字符串任意循环滑动之后,这些前缀都两两不同. 二分答案mid之后,将每个字符串长度为mid的循环子串都哈希出来,相当于对每个字符串,找一个与其他字符串所选定的子串不同的子串,是个二分图最大匹配的模型,可以匈牙利或者Dinic跑最大流看是否满流. 一个小优化是对于某个字符串,如果其所有不同的子串数量超过n,那么一定满足,可以直接删去. 卡常数,不能用set,map啥的,采取了用数组记录哈希值,排序后二分的手段进行去重和离散化. #include<cst

Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) E. Prairie Partition 二分+贪心

E. Prairie Partition It can be shown that any positive integer x can be uniquely represented as x = 1 + 2 + 4 + ... + 2k - 1 + r, where k and r are integers, k ≥ 0, 0 < r ≤ 2k. Let's call that representation prairie partition of x. For example, the p

【计算几何】【极角排序】【二分】Petrozavodsk Summer Training Camp 2016 Day 6: Warsaw U Contest, XVI Open Cup Onsite, Sunday, August 28, 2016 Problem J. Triangles

平面上给你n(不超过2000)个点,问你能构成多少个面积在[A,B]之间的Rt三角形. 枚举每个点作为直角顶点,对其他点极角排序,同方向的按长度排序,然后依次枚举每个向量,与其对应的另一条直角边是单调的,可以用一个pointer做出来,然后可以得出那些同方向的向量的区间(这个代码好像有点问题,可能会退化,最好确定了一个LL之后,对一个方向的不要重复算RR.这里如果也改成二分就比较好,复杂度不会退化).然后通过二分可以得到A使得面积在[A,B]间的有哪些(其实这个因为也是单调的,好像也没必要二分,

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案

There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebo

Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) C. Stairs and Elevators【二分查找】

In the year of 30XX30XX participants of some world programming championship live in a single large hotel. The hotel has nn floors. Each floor has mm sections with a single corridor connecting all of them. The sections are enumerated from 11 to mm alo

【枚举】【二分】【推导】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution

题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担给它们,要求每台服务器承担的资源需求不超过其所能提供的资源需求.给定一种合法的方案,每台服务器要么没有被分配给任何一个服务,或者被分配给其中一个服务. 对服务器按能提供的资源从小到大排序.枚举给S1分配的服务器数量i,然后在a数组中二分,就可以得到给S1提供的是哪i台服务器,它们占据了a数组中连续的