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

  1. 10 250
  2. 20 2500
  3. 25 7000
  4. 50 50000
  5. 0 0

Sample Output

  1. 8.054
  2. 14.775
  3. 13.115
  4. 30.901

Source

题目大意:告诉你圆柱直径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)

解题代码:

  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdio>
  4. using namespace std;
  5.  
  6. const double pi=acos(double(-1));
  7.  
  8. int main(){
  9. int d,v;
  10. while(cin>>d>>v && (d||v) ){
  11. double D=(double)d,V=(double)v;
  12. double tmp=D*D*D-6*V/pi;
  13. printf("%.3f\n",pow(tmp,1.0/3.0));
  14. }
  15. return 0;
  16. }

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

  1. poj 2405 Beavergnaw

    Beavergnaw Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6310   Accepted: 4158 Descri ...

  2. 2018.07.04 POJ 1654 Area(简单计算几何)

    Area Time Limit: 1000MS Memory Limit: 10000K Description You are going to compute the area of a spec ...

  3. 2018.07.04 POJ 3304 Segments(简单计算几何)

    Segments Time Limit: 1000MS Memory Limit: 65536K Description Given n segments in the two dimensional ...

  4. poj 1687 Buggy Sat 简单计算几何

    暑期集训出的第一道一血 感觉自己萌萌哒…… 这道题本身并没有坑点 仅仅是翻译巨坑…… 解大腿在做B 安学长在做E 我闲着也没事 就一个词一个词翻译F…… 最后感觉…… 题干大多数都看不懂…… 也都没啥 ...

  5. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  6. hdu 4720 计算几何简单题

    昨天用vim练了一道大水题,今天特地找了道稍难一点的题.不过也不是很难,简单的计算几何而已.练习用vim编码,用gdb调试,结果居然1A了,没调试...囧... 做法很简单,无非就是两种情况:①三个巫 ...

  7. POJ 2406 Power Strings 简单KMP模板 strcmp

    http://poj.org/problem?id=2406 只是模板,但是有趣的是一个strcmp的字符串比较函数,学习到了... https://baike.baidu.com/item/strc ...

  8. POJ 1844 Sum【简单数学】

    链接: http://poj.org/problem?id=1844 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=29256#probl ...

  9. A - TOYS(POJ - 2318) 计算几何的一道基础题

    Calculate the number of toys that land in each bin of a partitioned toy box. 计算每一个玩具箱里面玩具的数量 Mom and ...

随机推荐

  1. hdu1254(bfs+dfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1254 分析: 真正移动的是箱子,但是要移动箱子需要满足几个条件. 1.移动方向上没有障碍. 2.箱子后 ...

  2. URAL1113(数学)

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1113 根据样例分析: 1.沙漠只有500公里或者更短,这时很简单,一次搞定. 2.沙漠6 ...

  3. cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第八部---怪物出场

    /* 说明: **1.本次游戏实例是<cocos2d-x游戏开发之旅>上的最后一个游戏,这里用3.0重写并做下笔记 **2.我也问过木头本人啦,他说:随便写.第一别全然照搬代码.第二能够说 ...

  4. hdu 4925 贪心 自己从小到大做数据找方法规律

    http://acm.hdu.edu.cn/showproblem.php?pid=4925 自己逐个做数据找规律.提供下我的找的: 1 2 1 3 2 2 2 3 3 3 然后发现这种矩阵是最优的: ...

  5. Android 监听SMS短信

    当设备接收到一条新的SMS消息时,就会广播一个包括了android.provider.Telephony.SMS_RECEIVED动作的Intent. 注意,这个动作是一个字符串值,SDK 1.0不再 ...

  6. Conversion to Dalvik format failed: Unable to execute dex

    最近莫名奇妙遇到“Conversion to Dalvik format failed: Unable to execute dex”错误,stackoverflow以后得到结果 把项目中classp ...

  7. SWT中的GridLayout(转)例子不错

    GridLayout 是一个非常强大的布局管理器,它可以实现很多复杂的布局,名字中暗示它将所有控件放置在类似网格的布局中.^__^GridLayout 有两个构造函数. GridLayout的构造函数 ...

  8. Smarty中模板eq相等 ne、neq不相等, gt大于, lt小于

    eq相等   ne.neq不相等,   gt大于, lt小于 gte.ge大于等于   lte.le 小于等于   not非   mod求模   is [not] div by是否能被某数整除   i ...

  9. maven 打包 时出现非法字符: /65279错误

    maven 打包 时出现非法字符: /65279错误 碰到的一个问题: 使用下面的命令给工程打包时, maven mvn clean package -Ptest01 -Dmaven.test.ski ...

  10. scu - 3254 - Rain and Fgj(最小点权割)

    题意:N个点.M条边(2 <= N <= 1000 , 0 <= M <= 10^5),每一个点有个权值W(0 <= W <= 10^5),现要去除一些点(不能去掉 ...