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. Using std::map with a custom class key

    From: https://www.walletfox.com/course/mapwithcustomclasskey.php If you have ever tried to use a cus ...

  2. MySql之视图的使用

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

  3. JAVA中通过时间格式来生成唯一的文件名

    有时候我们需要截图,在要截图时,有人用到了时间格式,但是时间格式中的:在文件名称中是不被允许的字符,所以就会报错,如何生成唯一的时间文件名: package com.demo; import java ...

  4. iostat查看linux硬盘IO性能

    rrqm/s:   每秒进行 merge 的读操作数目.即 delta(rmerge)/swrqm/s:  每秒进行 merge 的写操作数目.即 delta(wmerge)/sr/s:        ...

  5. JAVA Spring boot相关技巧

    1. 注册多实例.@Scope("prototype") 2. 手工方式获取注册的实例. @Autowired private ServletContext servletCont ...

  6. 在Asp.Net中操作PDF – iTextSharp - 操作图片

    iTextSharp支持所有主流的图片格式,比如:jpg, tif, gif, bmp, png和wmf.在iTextSharp中使用Image.GetInstance()方法创建图片有很多种方式,或 ...

  7. Swift 同构与异构

    1.数据源中的同构与异构 对于 Swift 的集合数据来说,有同构和异构之分. 如果你需要讨论一群鸟类或者一批飞机,那么这样的数据是同构的,比如包含鸟类的数组 [Bird] 和包含飞机的数组 [Air ...

  8. intellij idea 显示打开文件路径按钮

  9. C#-MVC开发微信应用(3)--文本消息和图文消息的应答

    最近咨询微信的人很多,感觉这块也是一块商机,也为了演示SNF快速开发平台的优势,就用SNF快速开发平台开发出一套微信应用程序.使用<SNF.CodeGenerator>代码生成工具可以节省 ...

  10. EXP-00056: ORACLE error 12154 encountered

    今天用EXP命令导Oracle数据库,出现如下错误信息: [oracle@yingxiang-testServer1 ~]$ exp imgpf/imgpf@orcl file=/prlife/db/ ...