UVA10297 POJ2405 Beavergnaw【计算几何】
Beavergnaw
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6719 Accepted: 4367
Description
When chomping a tree the beaver cuts a very specific shape out of the tree trunk. What is left in the tree trunk looks like two frustums of a cone joined by a cylinder with the diameter the same as its height. A very curious beaver tries not to demolish a tree but rather sort out what should be the diameter of the cylinder joining the frustums such that he chomped out certain amount of wood. You are to help him to do the calculations.
We will consider an idealized beaver chomping an idealized tree. Let us assume that the tree trunk is a cylinder of diameter D and that the beaver chomps on a segment of the trunk also of height D. What should be the diameter d of the inner cylinder such that the beaver chmped out V cubic units of wood?
Input
Input contains multiple cases each presented on a separate line. Each line contains two integer numbers D and V separated by whitespace. D is the linear units and V is in cubic units. V will not exceed the maximum volume of wood that the beaver can chomp. A line with D=0 and V=0 follows the last case.
Output
For each case, one line of output should be produced containing one number rounded to three fractional digits giving the value of d measured in linear units.
Sample Input
10 250
20 2500
25 7000
50 50000
0 0
Sample Output
8.054
14.775
13.115
30.901
Source
问题链接:UVA10297 POJ2405 Beavergnaw
问题简述:一个底边和高为D的圆柱,被切去一部分使得剩下的圆柱和高为h,已知切去的体积v,求d。
问题分析:使用圆锥台体积公式进行计算,公式在代码中。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA10297 POJ2405 Beavergnaw */
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double PI = acos(-1);
int main()
{
double d, v;
while(~scanf("%lf%lf", &d, &v) && (d || v)) {
double tmp = d * d * d - v * 6 / PI;
printf("%.3f\n", exp(log(tmp) / 3));
}
return 0;
}
上一篇: UVA10678 The Grazing Cow【椭圆面积】
下一篇: JS 是什么意思