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
  1. #include<stdio.h>
  2. #include<math.h>
  3. #define e 0.0000001
  4. #define PI acos(-1.0)
  5. double V,r,H,R,h;
  6. double cc(double x,double th)
  7. {
  8. return PI*th*(x*x+x*r+r*r)/3.0;
  9. }
  10. void ccc(double ans)
  11. {
  12. double m,l,ri;
  13. l=0;ri=100.0;
  14. while(l+e<ri)
  15. {
  16. m=(l+ri)/2.0;
  17. if(cc(r+m*(R-r)/H,m)>ans)ri=m;
  18. else l=m;
  19. }
  20. h=m;
  21. }
  22. int main()
  23. {
  24. int t;
  25. scanf("%d",&t);
  26. while(t--)
  27. {
  28. scanf("%lf%lf%lf%lf",&r,&R,&H,&V);
  29. ccc(V);
  30. printf("%.6lf\n",h);
  31. }
  32. }

 

hdu2289Cup(神坑题,精度+二分,以半径二分不能过,以高度为二分就过了)的更多相关文章

  1. POJ 1064 Cable master(二分查找+精度)(神坑题)

    POJ 1064 Cable master 一开始把 int C(double x) 里面写成了  int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...

  2. bzoj千题计划316:bzoj3173: [Tjoi2013]最长上升子序列(二分+树状数组)

    https://www.lydsy.com/JudgeOnline/problem.php?id=3173 插入的数是以递增的顺序插入的 这说明如果倒过来考虑,那么从最后一个插入的开始删除,不会对以某 ...

  3. PAT甲题题解-1115. Counting Nodes in a BST (30)-(构建二分搜索树+dfs)

    题意:给出一个序列,构建二叉搜索树(BST),输出二叉搜索树最后两层的节点个数n1和n2,以及他们的和sum: n1 + n2 = sum 递归建树,然后再dfs求出最大层数,接着再dfs计算出最后两 ...

  4. 二分求解 三角形 stl的应用 涉及范围的二分查找可以先求上界再算下界,结果即上界减下界

     二分 Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu   Description You ...

  5. 【noip模拟题】挖掘机(模拟题+精度)

    这题直接模拟. 可是我挂在了最后两个点上QAQ.唯一注意的是注意精度啊...用来double后边转成整数就忘记用longlong...sad #include <cstdio> #incl ...

  6. JavaScript学习笔记6 之经典神坑题整理

    本篇内容是关于容易出错题的整理,这些题也有利于对javascript的语法逻辑的理解,分析的内容仅供参考: <script> */ var x=0 , y=0 , c=1; functio ...

  7. HDU5127 神坑题---vector 、 list 、 deque 的用法区别

    题意:三个操作 1  a b : 队列中加入(x = a, y = b); -1  a b : 队列中减去(x = a, y = b); 0  p q :从队列的数对中查询哪一对x,y能够让 p * ...

  8. July 【补题】

    A(zoj 3596) bfs,记忆搜都可以, 按余数来记录状态. B(zoj 3599) 博弈,跳过 C(zoj 3592) 简单dp,题意不好懂 D(zoj 3602) 子树哈希, 对根的左右儿子 ...

  9. [Codeforces 460C] Present

    [题目链接] https://codeforces.com/contest/460/problem/C [算法] 二分 + 贪心 要求最小值最大 , 我们不妨二分最小值 , 若一盆花的高度小于二分的值 ...

随机推荐

  1. <转>java编译问题:使用了未经检查或不安全的操作

    使用了未经检查或不安全的操作 在本人用editplus写java文件时碰到的问题.      源代码 import java.util.*; class collection{ public stat ...

  2. C#使用Windows API 隐藏/显示 任务栏 (FindWindowEx, ShowWindow)

    原文 C#使用Windows API 隐藏/显示 任务栏 (FindWindowEx, ShowWindow) 今天,有网友询问,如何显示和隐藏任务栏? 我这里,发布一下使用Windows API 显 ...

  3. Android之ListView性能优化

    ListView滚动速度优化主要可以应用以下几点方法来实现: 1.使用Adapter提供的convertView convertView是Adapter提供的视图缓存机制,当第一次显示数据的时候,ad ...

  4. sed(查找替换) 与awk(提取字段)

    通常: sed 处理列  awk处理行 比较方便 Sed是一个基本的查找替换程序     sed -i   "s/^@//g"     文件  #原地操作原文件,进行替换 cat ...

  5. nginx 重写 rewrite 基础及实例(转)

    nginx rewrite 正则表达式匹配 大小写匹配 ~ 为区分大小写匹配 ~* 为不区分大小写匹配 !~和!~*分别为区分大小写不匹配及不区分大小写不匹配 文件及目录匹配 -f和!-f用来判断是否 ...

  6. Sicily-1134

    一.      题意 按照孩子们需要的积木块数排序(从小到大),先处理需要积木块数少的孩子. 二.      代码 // // main.cpp // sicily-1134 // // Create ...

  7. Roman Roulette(约瑟夫环模拟)

    Roman Roulette Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  8. json数据的获取(网络摘抄)

    一个简单的对象: $.ajax({ type: "post", url: "Handler.ashx", dataType: "html", ...

  9. 前端CSS规范大全

    一.文件规范 1.文件均归档至约定的目录中(具体要求以豆瓣的CSS规范为例进行讲解): 所有的CSS分为两大类:通用类和业务类.通用的CSS文件,放在如下目录中: 基本样式库 /css/core 通用 ...

  10. JavaSE学习总结第11天_开发工具 & API常用对象1

      11.01 常见开发工具介绍 1:操作系统自带的记事本软件 2:高级记事本软件例:Editplus,Notepad++,UltraEdit 3:集成开发环境 IDE(Integrated Deve ...