博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ_ACM_CUP
阅读量:7113 次
发布时间:2019-06-28

本文共 3098 字,大约阅读时间需要 10 分钟。

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
1100 100 100 3141562
 
Sample Output
99.999024
 
 
Code
1 #include 
2 #include
3 #define PI acos(-1.0) 4 void main() 5 { 6 int count, i; 7 double min, max, midh, r, R, H, V, midR, resV; 8 scanf("%d", &count); 9 for (i = 0; i < count; i++)10 {11 scanf("%lf %lf %lf %lf", &r, &R, &H, &V);12 max = H;13 min = 0;14 while (max - min >= 1e-7)15 {16 midh = (max + min) / 2;17 midR = R * (midh * (R - r) + r * H) / (H * (R - r) + r * H);18 //if r is equal to R, it's cylinder 19 if (r == R)20 resV = PI * R * R * midh;21 else22 resV = PI / 3 * midh * (midR * midR + r * midR + r * r);23 //dichotomy24 if (fabs(V - resV) <= 1e-6)25 break;26 else if (resV > V)27 max = midh;28 else29 min = midh;30 }31 printf("%.6f\n", midh);32 }33 }

 

 以下代码,摘自其他网站
1 #include 
2 #include
3 #include
4 using namespace std; 5 double pi = acos(-1.0); 6 7 //知识点:圆台的体积公式V=pi*(r*r+r*R+R*R)*h/3 8 int main() 9 {10 int t;11 double r,R,H,V,h,h0,v0;12 scanf("%d",&t);13 while(t--)14 {15 scanf("%lf%lf%lf%lf",&r,&R,&H,&V);16 if(r==R)17 {18 h = V/(pi*r*r);19 }20 else if(r
H)h = H;27 printf("%.6f\n",h);28 }29 return 0;30 }

 

Key Point
Firstly, I should to emphasize that the mind is more crucial. Today I write down on the paper initially to get my ideas into shape so that I can finish in the morning.
Secondly, only when u couldn't get the exact answer directly will we use the dichotomy. For this question, I can find the  other solution from the others' blog, including the codes as above, which using the mathematics to solve. Even though I use the knowledge of math, but I just use the formula of the volume.

转载于:https://www.cnblogs.com/chuanlong/archive/2013/03/12/2955321.html

你可能感兴趣的文章
Redux
查看>>
774. Jewels and Stones
查看>>
在react-native中添加高可维护的iconfont字体
查看>>
java中反射机制的基本语法及练习
查看>>
mac 安装 lightgbm 无法导入(以及解决cmake命令无法编译)
查看>>
three.js快速入门和实战
查看>>
人人都能懂的Vue源码系列—09—initEvents
查看>>
express+nginx 搭建最简单web项目
查看>>
mpvue 小程序如何自定义tabBar,不使用navigateTo跳转,模拟redirectTo跳转
查看>>
以数据库思维理解区块链
查看>>
在Laravel中使用事件记录SQL查询到日志
查看>>
ABAP Netweaver和Hybris Enterprise Commerce Platform的登录认证
查看>>
vue elementUI 表单校验(多层嵌套)
查看>>
ionic3学习之目录结构分析
查看>>
教你如何修改github上的项目语言类型
查看>>
干货 | 手把手教你快速撸一个区块链
查看>>
github fork别人项目之后,更新和提交操作
查看>>
springboot 集成 swagger2 小记
查看>>
gorose orm+dotweb框架快速构建go web网站实战(一)
查看>>
npm-发布&管理module
查看>>