题目连接: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 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

题解:这是一道经典的二分的题,要注意在二分的时候对精度的判断和对特殊情况的考虑比如水溢出的情况。在推算公式的时候也要注意分母上的数不要有可能等于0 ,这就要求用更加合理的方法推算公式,这个题就是要用倾斜角来算比较好,这样分母上就是H不可能等于0;

代码:

 #include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define PI acos(-1)
#define eps 1e-8
double r , R , H , rr ,v,vv;
double f(double h)
{
return h*(R-r)/H+r;
}
double g(double rr,double h)
{
return (1.0/)*h*PI*(rr*rr+r*r+rr*r);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf %lf %lf %lf",&r,&R,&H,&v);
double tm = 1.0/*PI*H*(R*R+r*r+R*r);
double left= , right=H , mid = H/ ,vv = g(f(mid),mid);
if(tm<=v){
printf("%.6lf\n",H);
continue;//注意是continue还是break,因为这个哇了
}
else{
while(fabs(vv-v) > eps){
if(vv>v)
right = mid;
else
left = mid ;
mid = (left+right)/;
vv = g(f(mid),mid);
}
printf("%.6lf\n",mid);
}
}
return ;
}

Cup(二分)的更多相关文章

  1. HDU 2289 CUP 二分

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

  2. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  3. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3)(A.B.C,3道暴力题,C可二分求解)

    A. Is it rated? time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...

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

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

  5. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) A B C D 水 模拟 二分 贪心

    A. Is it rated? time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  6. 二分(HDU2289 Cup)

    贴代码: 题目意思:已知r水的下半径,R水的上半径,H为圆台高度,V为水的体积,求水的高度,如图: 水的高度一定在0-100,所以在这个区间逐步二分,对每次二分出的水的高度,计算相应的体积,看看计算出 ...

  7. HDU 2289 Cup【二分】

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

  8. 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 l ...

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

    题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...

随机推荐

  1. Android LayoutInflator 解析

    一.实际使用场景引入: 在ListView的Adapter的getView方法中基本都会出现,使用inflate方法去加载一个布局,用于ListView的每个Item的布局.  同样,在使用ViewP ...

  2. Win10关闭某程序的通知的方法

    一.点击右下角的通知图标. 二.点击所有通知. 三.点击系统 四.点击通知和操作 五.下拉,看到:获取来自这些发送者的通知 六.关闭自己想关闭通知的程序即可.

  3. Servlet小总结

    Servlet Servlet(服务器端小程序)是使用Java语言编写的服务器端程序,像JSP一样,生成动态的Web页.Servlet主要运行在服务器端,并由服务器调用执行. Servlet处理的基本 ...

  4. treeview插件使用:根据子节点选中父节点

    鄙人公司没有专门的前端,所以项目开发中都是前后端一起抡.最近用bootstrap用的比较频繁,发现bootstrap除了框架本身的样式组件外,还提供了多种插件供开发者选择.本篇博文讲的就是bootst ...

  5. Dos与Linux的断行字符

    Symptom Dos和Linux下面的断行字符是不一样的,至于哪里不一样的呢,先举个例子看一看 Cause 我们也可以使用cat -A filename分别查看Dos和Linux下创建的文件,会发现 ...

  6. [Upper case conversion ] 每个单词的首小写字母转换为对应的大写字母

    Given a string , write a program to title case every first letter of words in string. Input:The firs ...

  7. 细谈最近上线的Vue2.0项目(一)

    8月初离职,来到现在的新东家负责一个新的项目.而我最近开发的两个webapp一直都是以Vue为主,这也是这篇文章的由来. 正文前的胡侃&一点点吐槽 在经历了两个公司不同的项目后,发现都存在一个 ...

  8. Python学习(四):模块入门

    1.模块介绍 模块:代码实现的某个功能的集合 模块分类: 自定义模块 内置标准模块 开源模块 模块的常用方法: 是否为主文件:__name__ == '__main__' 如果是直接执行的某程序,那么 ...

  9. lesson - 11 正则表达式

    正则就是有一定规律的字符串,有几个特殊符号很关键(. * + ? | ),我们平时不仅可以用命令行工具grep/sed/awk去引用正则,而且还可以把正则嵌入在nginx.apache.甚至php.p ...

  10. SQL SERVER 日期转换大全

    博客转自:http://blog.csdn.net/baiduandxunlei/article/details/9180075 CONVERT(data_type,expression[,style ...