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. Two distinct points CodeForces - 1108A (签到)

    You are given two segments [l1;r1][l1;r1] and [l2;r2][l2;r2] on the xx-axis. It is guaranteed that l ...

  2. GitHub和Git超超超详细使用教程

    GitHub的简单使用第一步 创建GitHub账号1. 打开GitHub官网.2. 点击绿色按钮Sign up for GitHub,填写用户名,邮件地址和密码.注意: 用户名只能包含字母和" ...

  3. Mysql数据库中的日期相关操作

    1.获取当前时间的日期 select now();----------------------------------如:2008-12-29 16:25:46 select curdate();-- ...

  4. Nagios 系统监控

    Nagios 系统监控 Nagios 是一款免费的开源 IT 基础设施监控系统,功能强大,灵活性强,能有效监控 Windows.Linux.VMware 和 Unix 主机状态,交换机.路由器等网络设 ...

  5. 记第一次多用户在Git提交代码

    今天第一次进行了多用户(其实就两人)在自建Git服务器提交代码. 先记录碰到的问题:首先是本地提交代码时,进行了add,commit后,在push时碰到服务器故障,待设置好服务器后,再push时,却p ...

  6. CodeForces Round #550 Div.3

    http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains cons ...

  7. mysql 分库分表备份脚本

    #!/bin/bash USER=root #用户 PASSWORD=123456 #密码 MYSQL_PATH=127.0.0.1 #地址 MYSQL_BIN=/bin/mysql MYSQL_DU ...

  8. 关于Linux系统下jdk版本切换问题(alternatives命令的使用)

    [root@danny lib]# cd /usr/lib/jvm [root@danny jvm]# [root@danny jvm]# ls java java--openjdk-.b13.el7 ...

  9. JQ获取URL中是否含有某个字符的话,对页面进行某种操作

    一.//JQ获取URL中是否含有某个字符的话,对页面进行某种操作 例:如果URL中含有xia的字符,就在页面引入一个cssvar str=window.location.href; //获取地址栏UR ...

  10. python设计模式第六天【原型模式】

    1.定义 使用原型模式复制的对象与原来对象具有一样的结构和数据,有浅克隆和深克隆 2.应用场景 (1)希望复制原来对象的结构和数据胆步影响原来对象 3.代码实现 #!/usr/bin/env pyth ...