HDU 2289 Cup
来源:互联网 发布:知乎怎么匿名 编辑:程序博客网 时间:2024/06/06 03:12
Cup
Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u
Submit Status
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
- T ≤ 20.
- 1 ≤ r, R, H ≤ 100; 0 ≤ V ≤ 1000,000,000.
- r ≤ R.
- r, R, H, V are separated by ONE whitespace.
- 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
高中数学+二分
---------------- ----> R\ / \-----------/ ----> mid \ / \-----/ -----> r \ /
h为下方r为底的三角形的高
H为R为上底 r为下底的圆台的高
根据三角形相似性
R/(H+h)=r/h
<=> h=hr/(R-r)
r_mid/(mid+h)=r/h
<=> r_mid=mid*r/h+r
所以 根据锥体公式v=pi*h*(r*r+R*R+r*R)/3
二分求mid即可
#include<iostream>#include<cstdlib>#include<cstdio>#include<string>#include<vector>#include<deque>#include<queue>#include<algorithm>#include<set>#include<map>#include<stack>#include<ctime>#include<cmath>#include<list>#include<cstring>//#include<memory.h>using namespace std;#define ll long long#define ull unsigned long long#define pii pair<int,int>#define INF 1000000007#define pll pair<ll,ll>#define pid pair<int,double>#define sci(a) scanf("%d",&a)#define scll(a) scanf("%lld",&a)#define scd(a) scanf("%lf",&a)#define scs(a) scanf("%s",a)#define pri(a) printf("%d\n",a)#define prd(a) printf("%lf\n",a)#define prd4(a) printf("%.4lf\n",a)#define prd2(a) printf("%.2lf\n",a)#define prs(a) printf("%s\n",a)const double PI=4*atan(1);const double eps=1e-9;inline double cau_v(double R,double r,double h){//计算圆台体积 return PI*h*(R*R+R*r+r*r)/3.0;}double Bin_Search(double H,double R,double r,double h,double v){ double MIN=0,MAX=H; while(MAX-MIN>eps){ double mid=(MAX+MIN)/2; double r_mid=mid*r/h+r;//水的高度为mid时 水平面的半径 double vt=cau_v(r,r_mid,mid);//上底为r_mid 下底为r 高为mid的圆台体积 if(fabs(vt-v)<eps) return mid; else if(vt>v) MAX=mid; else MIN=mid; } return (MAX+MIN)/2;}int main(){ //freopen("/home/lu/文档/r.txt","r",stdin); //freopen("/home/lu/文档/w.txt","w",stdout); int t; sci(t); double r,R,h,v,H; while(t--){ scanf("%lf%lf%lf%lf",&r,&R,&H,&v); h=H*r/(R-r); prd(Bin_Search(H,R,r,h,v)); } return 0;}
- HDU 2289 Cup
- hdu 2289 CUP
- hdu 2289 cup
- hdu 2289 Cup
- hdu 2289 Cup (二分法)
- HDU 2289 Cup
- HDU 2289 Cup(二分)
- HDU 2289 Cup.
- HDU 2289 Cup 二分
- hdu 2289 Cup(二分)
- HDU 2289 cup
- HDU 2289 Cup
- HDU-2289 Cup
- HDU 2289 Cup
- HDU - 2289 CUP
- HDU 2289 Cup
- hdu 2289 Cup
- hdu-2289-Cup
- 通过反编译深入理解Java String及intern
- 2.chrome Network panel
- 如何在树霉派上配置XDMCP
- Eclipse启动报错A Java Runtime Environment or Java Developement Kit must be available in order to run ...
- 最小生成树的Prim算法笔记
- HDU 2289 Cup
- 将Sublime Text3添加到右键菜单中
- Linux安装speedtest-cli测试网速
- Java实习面试的那些事(四)
- 核心动画 -- CAAnimationGroup简介
- 改进版臭事百科爬虫
- 漫谈数据库索引
- 61. Rotate List
- HTML笔记