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
The radius of the cup's top and bottom circle is known, the cup's height is also known.
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.
100 100 100 3141562
题解:这是一道经典的二分的题,要注意在二分的时候对精度的判断和对特殊情况的考虑比如水溢出的情况。在推算公式的时候也要注意分母上的数不要有可能等于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(二分)的更多相关文章
- HDU 2289 CUP 二分
Cup Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
- 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 ...
- HDU 2289 Cup【高精度,二分】
Cup Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- 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 ...
- 二分(HDU2289 Cup)
贴代码: 题目意思:已知r水的下半径,R水的上半径,H为圆台高度,V为水的体积,求水的高度,如图: 水的高度一定在0-100,所以在这个区间逐步二分,对每次二分出的水的高度,计算相应的体积,看看计算出 ...
- HDU 2289 Cup【二分】
<题目链接> 题目大意: 一个圆台型的杯子,它的上底半径和下底半径已经给出,并且给出它的高度,问你,体积为V的水倒入这个杯子中,高度为多少. 解题分析: 就是简单的二分答案,二分枚举杯中水 ...
- 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 ...
- 【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution
题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...
随机推荐
- Run a task only once in (akka) cluster
在stackOverflow网站上看到这一提问,下文是部分摘抄问题简述: Java cluster, run task only once We have a java process, which ...
- scalajs_初体验
scalajs是将scala编译成js的编译器,目的在于使用scala的众多类库和强类型特征构建出稳定可扩展的js应用. build.sbt构建文件如下: enablePlugins(ScalaJSP ...
- 童话故事 --- 什么是SQL Server Browser
高飞狗这几天特别郁闷,不知该如何通过TCP/IP协议连接SQL Server数据库.好在功夫不负有心人,经过几天的刻苦研究,终于得到了答案. 高飞狗呼叫UDP1434端口,"叮铃铃,叮铃铃- ...
- 538. Convert BST to Greater Tree
Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original B ...
- AntData.ORM框架 之 DotnetCore
开源地址:https://github.com/yuzd/AntData.ORM CodeGen使用请参考http://www.cnblogs.com/yudongdong/p/6421312.h ...
- bzoj 2109: [Noi2010]Plane 航空管制
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...
- Linux目录结构介绍-http://yangrong.blog.51cto.com/6945369/1288072
1.树状目录结构图 2./目录 目录 描述 / 第一层次结构的根.整个文件系统层次结构的根目录. /bin/ 需要在单用户模式可用的必要命令(可执行文件):面向所有用户,例如:cat.ls.cp,和/ ...
- lambda表达式不使用委托(delegate) 用FUNC
lLambda不使用delegate关键字,而使用 Lambda运算符 => goes to l 1.Func<int,string> getInput = (int age ...
- java进程脱离终端运行
关于 java 进程脱离终端放入后台运行的问题,首先想到是使用nohup命令: 研究了一下tomcat启动脚本.jenkins.war启动方式以及其他linux命令,结论是在目前的linux系统上不使 ...
- 转 - .net/c# 使用RabbitMQ
背景 最近需要用C#写一个Adapter来做数据传输,合作方使用的是RabbitMQ,所以我这边也要跟着写写... 在网上搜索了一些,发现园子里的这篇写的还是非常好的.虽然有点老了,我自己用的是最新的 ...