POJ 2405 Beavergnaw (计算几何-简单题)

Beavergnaw

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6203   Accepted: 4089

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

Waterloo local 2002.07.01

题目大意:告诉你圆柱直径D,以及啃掉的面积V, 求d

解题思路:

简单的几何问题,够造体积相等,求未知数

V=直径为D的圆柱的体积-两个园台的体积-直径为d的圆柱的体积。

圆台体积公式 = 1/3* pi * (r1*r1 + r2*r2 + r1*r2)*h     r1,r2,h分别为圆台上低半径、下底半径和高

V=pi*(D/2)*(D/2)*D -     1/3 *( D*s1-d*s2   )     - pi*(d/2)*(d/2)*d

V=pi*(D/2)*(D/2)*D -     1/3 *pi(   D*D/4 + d*d/4 + D*d/4   )*( (D-d)/2)     - pi*(d/2)*(d/2)*d

V=pi*D*D*D/4 -      1/3 *pi(   D*D/4 + d*d/4 + D*d/4   )*(D/2 - d/2 )     - pi*d*d*d/4

V=pi*D*D*D/4 -      1/24 *pi(   D*D + d*d + D*d   )*(D - d )     - pi*d*d*d/4

V=pi*D*D*D/4 -      1/24 *pi(   D*D *D+ d*d*D + D*d*D - D*D*d - d*d*d - D *d *d)      - pi*d*d*d/4

V=pi*D*D*D/4 -      1/24 *pi(   D*D *D - d*d*d)      - pi*d*d*d/4

V=pi*D*D*D/6 - pi*d*d*d/6

d*d*d = D*D*D - 6*V/pi

d=( D*D*D - 6*V/pi )^(1/3)

解题代码:

#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

const double pi=acos(double(-1));

int main(){
    int d,v;
    while(cin>>d>>v && (d||v) ){
        double D=(double)d,V=(double)v;
        double tmp=D*D*D-6*V/pi;
        printf("%.3f\n",pow(tmp,1.0/3.0));
    }
    return 0;
}

POJ 2405 Beavergnaw (计算几何-简单题)

时间: 2024-10-01 02:38:14

POJ 2405 Beavergnaw (计算几何-简单题)的相关文章

POJ 2051 argus(简单题,堆排序or优先队列)

又是一道数据结构题,使用堆来进行权值调整和排序,每次调整都是o(n)的复杂度,非常高效. 第一眼看题觉得可以用优先队列来做,应该也很简单. 事实上多数优先队列都是通过堆来实现的. 写的时候还是出了一些问题: 1.二叉树根节点下标显然不能为0: 2.限界之后若出现扩界要小心: 3.在迭代循环比较的时候,尤其注意到底比较的是谁,别把自己绕晕了. ac代码: #include<iostream> #include<cstdio> #include<cstdlib> #incl

poj 1847 最短路简单题,dijkstra

1.poj  1847  Tram   最短路 2.总结:用dijkstra做的,算出a到其它各个点要改向的次数.其它应该也可以. 题意: 有点难懂.n个结点,每个点可通向ki个相邻点,默认指向第一个相邻点,可以改变指向.求一条从A到B的路,使用最少改变路上点的指向的次数. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm>

POJ 3619 Speed Reading(简单题)

[题意简述]:有K头牛,N页书,每次第i头牛每分钟只能读Si页书,连续读Ti分钟,之后休息Ri分钟.现在问我们第i头牛花费多少时间可以读完这N页书. [分析]:简单的模拟 //220K 32Ms #include<iostream> #include<cmath> using namespace std; int main() { double N,K,Si,Ti,Ri; cin>>N>>K; double a = N; for(int i = 0;i<

poj 2955 Brackets dp简单题

//poj 2955 //sep9 #include <iostream> using namespace std; char s[128]; int dp[128][128]; int n; int rec(int l,int r) { if(dp[l][r]!=-1) return dp[l][r]; if(l==r) return dp[l][r]=0; if(l+1==r){ if(s[l]=='('&&s[r]==')') return dp[l][r]=2; if(

poj 2405 Beavergnaw

Beavergnaw Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6310   Accepted: 4158 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 co

POJ 2575 Jolly Jumpers(简单题)

[题意简述]:将数列中相邻的两个数做差,判断得到的绝对值是否是1,2,--,n-1,如果是的话,则是Jolly ,否则not jolly. [分析]:开始时没有仔细看题,没有看到时相邻的两个数做差,以为任意两两做差. 而后重新分析题目后,解决了这道题目,我们可以使用一个标志数组来帮助我们储存得到的做差的绝对值的值,最后,我们只需要扫描一下这个数组看是否从1,2,--,n-1都有值与之相对应. 详见代码: // 324K 47Ms #include<iostream> #include<c

POJ 3589 Number-guessing Game(简单题)

[题目简述]:两个四位数,假设后一个数中的某个数与前一个相应的数的位置和值都相等.则统计数目由几个这种数.记为count1吧. 假设后一个数中的某个数与前一个数的数值相等,但位置不同. 此时这种数的个数记为count2. 写成*A*B,即count1 A count2 B. [分析]:题目的简述即分析. //740K 0Ms #include<iostream> #include<cstring> using namespace std; int main() { int T; s

POJ 3299 Humidex(简单题)

[题意简述]:就是什么温度,湿度--,之间的转换.. [分析]:公式已给出了. // 252k 0Ms /* 其中exp表示的是求e的x次幂 解法就直接根据题目中的公式解决就好!! */ #include<iostream> #include<iomanip> #include<cmath> using namespace std; int main() { double t,d,h; char alpha; while(1) { t = d = h = 101; fo

POJ 2664 Prerequisites?(简单题)

[题意简述]:k:已经选择的科目数:m:选择的科目类别:c:可以选择的科目数:r:要求最少选择的科目数量 在输入的k和m下面的一行是选择的科目号. 例如: 3 2 //3是他选择了3科,2表示选择了两个类别 0123 9876 2222 //这是他选择的具体的3科科目的科目号 2 1 8888 2222 //其中2表示在这个类别里共有两科8888和2222,然后最少要选择这两个中的一个 3 2 9876 2222 7654 //这是第二个类别,含义同上. 具体代码: //208K 500Ms #