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.0)πh(RR+rr+rR)

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include <iomanip>
  5. #include<cmath>
  6. #include<float.h>
  7. #include<string.h>
  8. #include<algorithm>
  9. #define sf scanf
  10. #define pf printf
  11. #define pb push_back
  12. #define mm(x,b) memset((x),(b),sizeof(x))
  13. #include<vector>
  14. #include<map>
  15. #define for(i,a,b) for(int i=a;i<b;i++)
  16. typedef long long ll;
  17. typedef long double ld;
  18. typedef double db;
  19. const ll mod=1e12+100;
  20. const db e=exp(1);
  21. using namespace std;
  22. const double pi=acos(-1.0);
  23. db V,r,R,H;
  24. int judge(db mid)
  25. {
  26. db rr=(R-r)*mid/H+r;
  27. db v=(1/3.0)*pi*mid*(rr*rr+r*r+rr*r);
  28. if(v==V) return 0;
  29. if(v>V) return 1;
  30. return -1;
  31. }
  32. int main()
  33. {
  34. int re;
  35. cin>>re;
  36. while(re--)
  37. {
  38. sf("%lf%lf%lf%lf",&r,&R,&H,&V);
  39. db right=H,left=0,mid;
  40. while(right-left>0.00000001)
  41. {
  42. mid=(left+right)/2;
  43. if(judge(mid)==0)
  44. break;
  45. else if(judge(mid)>0)
  46. right=mid;
  47. else
  48. left=mid;
  49. }
  50. pf("%.6lf\n",mid);
  51. }
  52. return 0;
  53. }

E - Cup的更多相关文章

  1. java高cup占用解决方案

    项目中发现java cpu占用高达百分之四百,查看代码发现有一个线程在空转,拉高了cup while(true){ } 解决方案,循环中加入延迟:Thread.sleep(Time): 总结下排查CP ...

  2. UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  3. uva 6757 Cup of Cowards(中途相遇法,貌似)

    uva 6757 Cup of CowardsCup of Cowards (CoC) is a role playing game that has 5 different characters (M ...

  4. 【转】关于KDD Cup '99 数据集的警告,希望从事相关工作的伙伴注意

    Features From: Terry Brugger Date: 15 Sep 2007 Subject: KDD Cup '99 dataset (Network Intrusion) cons ...

  5. Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告

    Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: ...

  6. DP VK Cup 2012 Qualification Round D. Palindrome pairs

    题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 ...

  7. [BZOJ 3145][Feyat cup 1.5]Str 解题报告

    [Feyat cup 1.5]Str DescriptionArcueid,白姬,真祖的公主.在和推倒贵看电影时突然对一个问题产生了兴趣:我们都知道真祖和死徒是有类似的地方.那么从现代科学的角度如何解 ...

  8. HDU 2289 CUP 二分

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

  9. VK Cup 2012 Round 3 (Unofficial Div. 2 Edition)

    VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) 代码 VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) A ...

  10. UVALive 7275 Dice Cup (水题)

    Dice Cup 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/D Description In many table-top ...

随机推荐

  1. 一步一步开发sniffer(Winpcap+MFC)(五)莫道无人能识君,其实我懂你的心——解析数据包(转)

    前文已经讲过,解析数据包主要通过analyze_frame()这个函数实现的,实际上并非这个函数完成了所有的功能,其实从名字就可以看出,它只是完成了对“帧”的解析,也就是链路层数据的解析,还有anal ...

  2. Android GUI之Activity、Window、View

    相信大家在接触Android之初就已经知道了Activity中的setContentView方法的作用了,很明显此方法是用于为Activity填充相应的布局的.那么,Activity是如何将填充的布局 ...

  3. 五花八门的Shell 的相关概念和配置方法

    使用Linux的过程中少不了使用各种各样的Shell, 而根据启动环境的不同,Shell会读取不同的配置文件. 本文便来详细介绍这些不同名字的配置文件在何时会被Shell读取. 什么是 Shell S ...

  4. AI通过了艺术创作图灵测试,你根本分不出来作者是不是人

    各位geek朋友们,今年不用再看画了:近年来最大的艺术成就已经发生了. 这项艺术成就的诞生地,不是北京.新加坡.柏林郊区颜料四溅的画室中,不是威尼斯双年展上.请记住它出现的地点:美国新泽西州新布朗斯维 ...

  5. 解决Nginx的13: Permission denied) while connecting to upstream

    一.问题 做Nginx负载的时候,经常遇到这样的情况: // :: [crit] #: * connect() to failed (: Permission denied) while connec ...

  6. Nginx的安装和设置

    Nginx是一个高性能的HTTP服务器和反向代理服务器.当一个服务器访问量太大时(比如C10k问题,Concurrent 10,000 Connection),就可以安装设置一个Nginx服务器,将客 ...

  7. MySql之视图的使用

    一:视图是什么 视图相当于一个窗口,一个基于具体数据库表.定义了相关查询规则 的窗口. 建立视图,可以重用一些复杂的查询语句.    建立视图,相当于定义了一系列查询操作:从视图查询数据,相当于在调用 ...

  8. 《Unix&Linux大学教程》学习笔记四:标准I/O 与 过滤器

    1:标准IO Unix中的标准IO主要包括:标准输入.标准输出(正常输出).标准错误(异常信息) 2:重定向输出 内容 > 文件名 :将内容输出到文件,并且覆盖文件原来内容:文件不存在则新建 内 ...

  9. Swap 分区的2种方式 详解与例子

    安装完Linux系统后,swap分区太小怎么办,怎么可以扩大Swap分区呢?有两个办法,一个是从新建立swap分区,一个是增加swap分区.下面介绍这两种方法: 第一您必须有root权限,过程中一定要 ...

  10. 关于ř与tableau的集成---- k均值聚类

    1.利用R内置数据集iris: 2.通过Rserve 包连接tableau,服务器:localhost,默认端口6311: 3.加载数据集iris: 4.编辑字段:Cluster <span s ...