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

The 4th Baidu Cup final


思路

高精度二分的题目,注意圆台的体积公式为\(V=\frac{1}{3}\pi h(R^2+r^2+Rr)\)

不断二分查找最接近的h就好了,详见代码

代码

#include<bits/stdc++.h>
#define M_PI 3.14159265358979323846
using namespace std;
double r,R,H,V;
const double eps = 1e-8;
double cal(double h)
{
double t = r + (R-r)*h/H;//求出h高度对应的截面的圆的半径
return M_PI*h*(t*t + r*r + t*r)/3;
}
int main()
{
int t;
cin >> t;
while(t--)
{
cin >> r >> R >> H >> V;
double ans = 0;
double l = 0, r = 100.0;
double mid;
while(r-l>=eps)
{
mid = (l+r)/2;
if(cal(mid)<V)
l = mid;
else
r = mid;
}
printf("%.6lf\n",l);
}
return 0;
}

Hdoj 2289.Cup 题解的更多相关文章

  1. 二分搜索 HDOJ 2289 Cup

    题目传送门 /* 二分搜索:枚举高度,计算体积与给出的比较. */ #include <cstdio> #include <algorithm> #include <cs ...

  2. 【HDOJ】2289 Cup

    二分.另外,圆台体积为v = PI*(r*r+r*R+R*R)*H/3.注意精度. #include <cstdio> #include <cmath> #define exp ...

  3. HDU 2289 Cup【高精度,二分】

    Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. HDU 2289 CUP 二分

    Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. HDU 2289 Cup

    Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. hdu 2289 Cup (二分法)

    http://acm.hdu.edu.cn/showproblem.php?pid=2289 二分法解题. 这个题很恶心...一开始测试样例都不能过,这个π一开始取3.1415926结果是99.999 ...

  7. HDU 2289 Cup(可以二分法,但是除了它的一半?)

    这道题目.运营商做数学题?算上两个子主题做?顶多算一个水主要议题... 首先,没有实际的二分法,但是,我们发现了一个新的解决方案,以取代二分法. 若果按照i从0,每次添加0.00000001我一直枚举 ...

  8. Hdoj 1425.sort 题解

    Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含 ...

  9. HDU 2289 Cup【二分】

    <题目链接> 题目大意: 一个圆台型的杯子,它的上底半径和下底半径已经给出,并且给出它的高度,问你,体积为V的水倒入这个杯子中,高度为多少. 解题分析: 就是简单的二分答案,二分枚举杯中水 ...

随机推荐

  1. 漫谈数组去重复方法(亮点是ES6的新API)

    方法1: 利用遍历的思想来进行. <!DOCTYPE html><html lang="en"><head> <meta charset= ...

  2. eclipse如何添加web dynamic project

    很多eclipse版本是不能直接新建web dynamic project的,需要从网上找插件或更新. 比较方便的是在Help → Install-New-Software,点击add按钮,在Loca ...

  3. Python_程序实现发红包

    发红包 200块钱  20个红包 将200块随机分成20份 基础版本: import random ret = random.sample(range(1, 200 * 100), 19) ret = ...

  4. Liunx 简单的命令说明

    cd命令在linux中用来切换或者进入目录,路径还分为相对路径和绝对路径 cd 命令:切换当前目录至其他目录 cd /:加上斜杠表示是进入到根目录. pwd命令:查看当前路径. ()cd 进入用户主目 ...

  5. #Leetcode# 524. Longest Word in Dictionary through Deleting

    https://leetcode.com/problems/longest-word-in-dictionary-through-deleting/ Given a string and a stri ...

  6. spring后置处理器BeanPostProcessor

    BeanPostProcessor的作用是在调用初始化方法的前后添加一些逻辑,这里初始化方法是指在配置文件中配置init-method,或者实现了InitializingBean接口的afterPro ...

  7. C# Note30: 软件加密机制以及如何防止反编译

    参考文章: C#软件license管理(简单软件注册机制) 软件加密技术和注册机制 .NET中的许可证机制--License 背景 .net是一种建立在虚拟机上执行的语言,它直接生成 MSIL 的中间 ...

  8. python设计模式第十九天【职责链模式】

    1.应用场景 (1)将一个任务拆分为具有顺序的多个部分,每个类完成相应的部分,并且顺序执行 (2)软件窗口的消息传播 (3)SERVLET容积的过滤器Filter的实现 2.代码实现 #!/usr/b ...

  9. Java对象clone()的测试

    Object中自带native clone()方法. 研究了一下用法. public class DeepCopyTest { public static void main(String[] arg ...

  10. 开发中遇到的css兼容问题

    1. overflow: scroll(平台兼容) 在Mac中的Chrome浏览器中,内容不超过容器时不会出现滚动条: 在Wins中的Chorme浏览器中,内容不超过容器时也会出现滚动条. 解决方法: ...