Cup

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

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
 
Recommend
分析:二分,对高度进行二分,然后我们知道圆台的公式为V=pi/3*(r*r+u*u+r*u)*h;然后可二分解决!这题精度比较坑爹,所以稍微注意点就好了!
下面给出AC代码:
 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')
f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
inline void write(int x)
{
if(x<)
{
putchar('-');
x=-x;
}
if(x>)
{
write(x/);
}
putchar(x%+'');
}
const double pi=acos(-1.0);
const double eps=1e-;
double r,R,h,H,V;
inline double check(double r,double R,double h,double H)
{
double u=h/H*(R-r)+r;
return pi*1.0*(r*r+u*u+u*r)*h/;
}
int main()
{
int n;
n=read();
while(n--)
{
scanf("%lf%lf%lf%lf",&r,&R,&H,&V);
double L1=0.0;
double R1=100.0;
double mid;
while(L1+eps<R1)
{
mid=(L1+R1)/;
double vv=check(r,R,mid,H);
if(fabs(vv-V)<=eps)
break;
else if(vv>V)
R1=mid-eps;
else L1=mid+eps;
}
printf("%.6lf\n",mid);
}
return ;
}

HDU 2289 Cup【高精度,二分】的更多相关文章

  1. HDU 2289 Cup【二分】

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

  2. HDU 2289 CUP 二分

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

  3. hdu 2289 Cup (二分法)

    http://acm.hdu.edu.cn/showproblem.php?pid=2289 二分法解题. 这个题很恶心...一开始测试样例都不能过,这个π一开始取3.1415926结果是99.999 ...

  4. HDU 2289 Cup

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

  5. HDU 2289 Cup(可以二分法,但是除了它的一半?)

    这道题目.运营商做数学题?算上两个子主题做?顶多算一个水主要议题... 首先,没有实际的二分法,但是,我们发现了一个新的解决方案,以取代二分法. 若果按照i从0,每次添加0.00000001我一直枚举 ...

  6. Hdoj 2289.Cup 题解

    Problem Description The WHU ACM Team has a big cup, with which every member drinks water. Now, we kn ...

  7. POJ 2109 Power of Cryptography【高精度+二分 Or double水过~~】

    题目链接: http://poj.org/problem?id=2109 参考: http://blog.csdn.net/code_pang/article/details/8263971 题意: ...

  8. 二分搜索 HDOJ 2289 Cup

    题目传送门 /* 二分搜索:枚举高度,计算体积与给出的比较. */ #include <cstdio> #include <algorithm> #include <cs ...

  9. hdu 2289 要二分的杯子

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2289 大意是 一个Cup,圆台形,给你它的顶部圆的半径,底部圆的半径,杯子的高度,和此时里面装的水的体 ...

随机推荐

  1. Memcached的简介和使用

    缘起: 在数据驱动的web开发中,经常要重复从数据库中取出相同的数据,这种重复极大的增加了数据库负载.缓存是解决这个问题的好办法.但是ASP.NET中的虽然已经可以实现对页面局部进行缓存,但还是不够灵 ...

  2. rpm 命令详解

    参考:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/10/08/2203153.html rpm是由红帽公司开发的软件包管理方式,使用r ...

  3. lesson - 4 笔记 /inode / suid / sgid / sbit / chmod /umask / chown / rwx / wc /grep / tr / sort / cut /which / whereis / locate / find / ln /

    一.帮助+基本文件管理+用户管理 1.怎么查看命令帮助 ls --help man ls :查看命令/man 5 file:查看配置文件 二.基本文件管理,通过{查,建,删,改} 四个维度介绍了不同的 ...

  4. 不写一行代码,利用常用工具和软件批量下载URL资源

    有时候会遇到这种情况:想从某个网站下载一批东西,目标URL是比较规整的,而且结构都一样(仅某些字段不同).但又懒得开IDE专门写个脚本去弄,今天就和大家分享一下,如何利用手边常用的软件和工具,不用写一 ...

  5. 更好的小票打印体验,huanent.printer2.0发布

    huanent.printer2.0是一个专注消费小票打印的类库.拥有许多先进的特性例如居中打印.自动换行等特性,可以通过简洁的代码来打印出复杂的消费小票.huanent.printer通过MIT方式 ...

  6. socket对象放在一个datagridview的row的tag里面在拿出来 为什么是已释放

     socket对象放在一个datagridview的row的tag里面在拿出来 为什么是已释放 

  7. 通过window.location.search获取页面url传递的参数

    function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...

  8. Java第一章----Java概述+环境搭建

    写在前面的话: Java基础的东西看过好几遍,但是过一段都就忘记了,所以这次我决定花费一些时间整理一个系列博客供以后方便查阅.此系列根据Java编程思想+Java核心技术两本书整理而来,这两本书也是我 ...

  9. python3之正则表达式

    1.正则表达式基础 正则表达式是用于处理字符串的强大工具,拥有自己独特的语法以及一个独立的处理引擎,效率上可能不然str自带方法,但功能十分强大. 正则表达式的大致匹配流程:依次拿出表达式和文本中的字 ...

  10. 【有上下界的网络流】ZOJ2341 Reactor Cooling(有上下界可行流)

     Description The terrorist group leaded by a well known international terrorist Ben Bladen is bulidi ...