Cup

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8946    Accepted Submission(s): 2747

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
 
 

题意就是已知一个杯子的下底和上底,高度,还知道水的体积,要求水在杯子里的高度。圆台的体积公式V=1/3π(R*R+r*r+R*r),如果r==R,那就是圆柱,圆柱的体积就是圆台的体积的特殊情况嘛。

一个坑就是水在杯子里的上底要相似三角形算出来,哇,垃圾。。。还有一个就是π的精度要准确一些acos(-1.0)。

二分二分!!!

代码:

#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0); //精度很重要
const double eps=1e-; //精度很重要
int n;
double r,R,u,H,V;
double l,rr,mid; double gg(double h){
u=h/H*(R-r)+r; //相似三角形算出来上面的半径
return pi/*h*(r*r+u*u+r*u); //体积公式
}
int main(){
while(~scanf("%d",&n)){
while(n--){
cin>>r>>R>>H>>V;
l=;rr=H;
while(rr-l>=eps){ //二分
mid=(l+rr)/;
if(gg(mid)<=V)
l=mid;
else
rr=mid;
}
printf("%.6lf\n",mid);
}
}
return ;
}

HDU2289-Cup-二分的更多相关文章

  1. 二分(HDU2289 Cup)

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

  2. HDU 2289 CUP 二分

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

  3. HDU题解索引

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

  4. 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 ...

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

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

  6. Cup(二分)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2289 hdu_2289:Cup Time Limit: 3000/1000 MS (Java/Othe ...

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

  8. HDU 2289 Cup【二分】

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

  9. 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 ...

  10. 【枚举】【二分】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. Java I/O---序列化接口Serializable

    1.JDK API 中关于Serializable的描述 public interface Serializable 类通过实现 java.io.Serializable 接口以启用其序列化功能.未实 ...

  2. 历年NOIP选题题解汇总

    联赛前上vijos板刷往年联赛题,使用在线编辑编写代码,祝我rp++. 废话不多说,挑比较有意思的记一下. 题目是按照年份排序的,最早只到了03年. 有些题目因为 我还没写/很早之前写的忘了 所以就没 ...

  3. Windows as a Service(2)—— 使用WSUS管理Windows10更新

    前言 在上一篇Windows as a Service(1)-- Windows 10服务分支中,我和大家分享了Windows 10三个服务分支CB/CBB/LTSB的概念及不同,从这篇文档开始,我将 ...

  4. deepin系统下安装git

    1.打开命令行 2.输入 sudo apt-get update sudo apt-get install git 3.显示 建议安装: git-daemon-run | git-daemon-sys ...

  5. a 标签的四种样式

    在支持 CSS 的浏览器中,链接的不同状态都可以不同的方式显示,这些状态包括:活动状态,已被访问状态,未被访问状态,和鼠标悬停状态.分别如下设置: a:link {color: red} /* 未访问 ...

  6. Python第二十天 shutil 模块 zipfile tarfile 模块

    Python第二十天  shutil 模块  zipfile   tarfile 模块 os文件的操作还应该包含移动 复制  打包 压缩 解压等操作,这些os模块都没有提供 shutil 模块shut ...

  7. Python学习_09_模块

    模块 模块是python中的最高组织单元,在物理层面上,模块以文件存储,模块的文件名就是模块的名字.py,每个模块都有自己的名称空间. python按照路径搜索来查找模块文件,在PYTHONPATH环 ...

  8. Head First设计模式之观察者模式

    一.定义 观察者设计模式定义了对象间的一种一对多的依赖关系,以便一个对象的状态发生变化时,所有依赖于它的对象都得到通知并自动刷新. 有时被称作发布/订阅模式,观察者模式定义了一种一对多的依赖关系,让多 ...

  9. 利用lsof恢复进程占用的文件

    说明:经常会遇到这种情况,没有使用正确的方式清理进程占用的文件,比如日志.导致空间并没有释放.也有的时候需要恢复进程占用的文件. 解决方式 lsof |grep del # 找出自己要恢复的文件名称. ...

  10. 阻止form空表单提交----JavaScript

    网上看到很不错的阻止form空表单提交 第一种方法 <div class="warp"> <h2>登录到pfan空间</h2> <p> ...