Hdoj 2289.Cup 题解
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
- T ≤ 20.
- 1 ≤ r, R, H ≤ 100; 0 ≤ V ≤ 1000,000,000.
- r ≤ R.
- r, R, H, V are separated by ONE whitespace.
- 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
思路
高精度二分的题目,注意圆台的体积公式为\(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 题解的更多相关文章
- 二分搜索 HDOJ 2289 Cup
题目传送门 /* 二分搜索:枚举高度,计算体积与给出的比较. */ #include <cstdio> #include <algorithm> #include <cs ...
- 【HDOJ】2289 Cup
二分.另外,圆台体积为v = PI*(r*r+r*R+R*R)*H/3.注意精度. #include <cstdio> #include <cmath> #define exp ...
- HDU 2289 Cup【高精度,二分】
Cup Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 2289 CUP 二分
Cup Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 2289 Cup
Cup Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 2289 Cup (二分法)
http://acm.hdu.edu.cn/showproblem.php?pid=2289 二分法解题. 这个题很恶心...一开始测试样例都不能过,这个π一开始取3.1415926结果是99.999 ...
- HDU 2289 Cup(可以二分法,但是除了它的一半?)
这道题目.运营商做数学题?算上两个子主题做?顶多算一个水主要议题... 首先,没有实际的二分法,但是,我们发现了一个新的解决方案,以取代二分法. 若果按照i从0,每次添加0.00000001我一直枚举 ...
- Hdoj 1425.sort 题解
Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含 ...
- HDU 2289 Cup【二分】
<题目链接> 题目大意: 一个圆台型的杯子,它的上底半径和下底半径已经给出,并且给出它的高度,问你,体积为V的水倒入这个杯子中,高度为多少. 解题分析: 就是简单的二分答案,二分枚举杯中水 ...
随机推荐
- redis 的使用,及如何使用redis维护数亿人的登录状态
一.redis中几个常用的方法 redis的使用场景移步本文 select db redis 下默认有有16个表,0~15可以通过:select 2 或者 select 11这样的方式切换表 keys ...
- 多线程系列之十:Future模式
一,Future模式 假设有一个方法需要花费很长的时间才能获取运行结果.那么,与其一直等待结果,不如先拿一张 提货单.获取提货单并不耗费时间.这里提货单就称为Future角色获取Future角色的线程 ...
- php开发之常用验证方法
1.邮箱验证 function isEmail($email) { if (!$email) { return false; } return preg_match('/^[_\.0-9a-z-]+@ ...
- # 【Python3练习题 007】 有一对兔子,从出生后第3个月起每个月都生一对兔子, # 小兔子长到第三个月后每个月又生一对兔子, # 假如兔子都不死,问每个月的兔子总数为多少?
# 有一对兔子,从出生后第3个月起每个月都生一对兔子,# 小兔子长到第三个月后每个月又生一对兔子, # 假如兔子都不死,问每个月的兔子总数为多少?这题反正我自己是算不出来.网上说是经典的“斐波纳契数列 ...
- Java 中的String、StringBuilder与StringBuffer的区别联系(转载)
1 String 基础 想要了解一个类,最好的办法就是看这个类的源代码,String类源代码如下: public final class String implements java.io.Seria ...
- redis 的简单命令
以下实例讲解了如何启动 redis 客户端: 启动 redis 客户端,打开终端并输入命令 redis-cli.该命令会连接本地的 redis 服务. $redis-cli redis > re ...
- python之路--动态传参,作用域,函数嵌套
一 . 动态传参(重点) * , ** * 与 ** * 在形参位置. * 表示不定参数, 接收的是位置参数 接收到的位置参数的动态传参: 都是元组 def eat(*food): # 在形参这里 ...
- HTML5 History API & URL 重定向
HTML5 History API & URL 重定向 disabled server url redirect https://developer.mozilla.org/en-US/doc ...
- 由 POST 400 错误拔出来的萝卜
缘起 前段时间遇到扫描问题,好不容易拿到了扫描出来的数据,结果调用接口时弹了个 400(Bad request) 给我,匆匆找了点资料修补上线后,忐忑的心也可以安分点.然后,顺着这个 400 的萝卜, ...
- Nginx stream ssl
L 115 端口监听 netstat -anp | (端口名)