题目连接: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. RabbitMQ阻塞读取时数据时,关闭channel引起的问题和解决方案

    项目场景: 最近在项目中使用了RabbitMq,其中有一个功能必须能随时切断RabbitMq的coumser.第一时间写出来的代码如下: 伪代码: while(flag){ QueueingConsu ...

  2. java推送数据到app--极光推送

    之前项目有用到需要把数据推送到app端 采用的是极光推送 特此把工具类和pom.xml需要的jar整理如下 pom.xml需要jar如下 <!-- 极光推送 --> <depende ...

  3. 基于Docker的ELK日志平台搭建

    1.安装Docker Docker可简单理解为一个轻量级的虚拟机.Docker对进程进行封装隔离,隔离的进程独立于宿主和其它的隔离的进程,因此也称其为容器.Docker和传统虚拟化方式的不同.传统虚拟 ...

  4. NOI 2005维护数列

    题目描述 请写一个程序,要求维护一个数列,支持以下 6 种操作:(请注意,格式栏 中的下划线‘ _ ’表示实际输入文件中的空格) 输入输出格式 输入格式: 输入文件的第 1 行包含两个数 N 和 M, ...

  5. commons-dbutils 字段名称转换

    我们在写bean的时候,字段通常都使用小驼峰命名法,但是在设计数据库时,一般使用下划线分割命名.这样,在取出数据库字段时,还需要转换.如何简洁的实现这种转换呢? 你能遇到的问题,只要是普遍存在的,大家 ...

  6. JQuery基本语法(部分)

    1.jQuery介绍 jQuery 是一个 JavaScript 函数库. jQuery 库包含以下特性: HTML 元素选取 HTML 元素操作 CSS 操作 HTML 事件函数 JavaScrip ...

  7. Struts2学习笔记(1)---相关配置

    Struts 2是Struts的下一代产品,是在 struts 1和WebWork的技术基础上进行了合并的全新的Struts 2框架. 1创建action对象(三种) 1 创建普通的类,不继承任何类, ...

  8. Protobuf使用(一)

    Protobuf使用(一)   前言:   最近由于接手一个支付的项目,他们那边的网络请求和数据解析都与我平常接触的项目不同,数据请求由于保密暂时不能说,但是数据解析用的是Protobuf,于是我就顺 ...

  9. MySQL 基础命令

    的说法啊打发 第1章 SQL语句 mysql版本:针对mysql-5.6.36 版本 (5.7会有一些变动) 1.1 常用命令 # 查看数据库 mysql> show databases; sh ...

  10. python爬虫入门-开发环境与小例子

    python爬虫入门 开发环境 ubuntu 16.04 sublime pycharm requests库 requests库安装: sudo pip install requests 第一个例子 ...