Beavergnaw

Question

Solution

Idea

This is purely a math problem, a math problem about the solid geometry. Quite boring since it took me a while to derive the math formula. The steps are summarised as follows:

  1. Calculate the volumne of the bigger cylinder total, which is π(D2)2D\pi*(\frac{D}{2})^2*D

  2. Use total minus the input V to get the volume of the wood eaten by the beaver, wood=totalv\text{wood}=\text{total}-\text{v}

Now the trickiest thing begins, we need to deduct the two truncated cone. Here we use the bigConesmallCone\text{bigCone}-\text{smallCone} to calculate. And we first consider the upper half.

Notice that for the upper half, the bigCone\text{bigCone} is with both radius and height as D2\frac{D}{2}, while the smallCone\text{smallCone} is with both radius and height as d2\frac{d}{2}. So, the volume for the upper truncated cone should be 13(π(D2)3π(d2)3)\frac{1}{3}(\pi(\frac{D}{2})^3-\pi(\frac{d}{2})^3).

So, for the two truncated cones, their total volume should be 23(π(D2)3π(d2)3)\frac{2}{3}(\pi(\frac{D}{2})^3-\pi(\frac{d}{2})^3), which is same as 13(π(D2)2Dπ(d2)2d)\frac{1}{3}(\pi(\frac{D}{2})^2\cdot D-\pi(\frac{d}{2})^2\cdot d).

Notice that the volumne of two truncated cones plus the volume of the inner cylinder will be the volumne of wood\text{wood}. And the volumne of the cylinder is given by π(d2)2d\pi(\frac{d}{2})^2\cdot d, which can be simplify to 2πr3,where r=d22\pi r^3,\text{where }r=\frac{d}{2}. (Now, you should be able to solve for the dd). Manipulate the formula, we have 23(2πr3)=wood13π(D22)D\frac{2}{3}(2\pi r^3)=\text{wood}-\frac{1}{3}\pi(\frac{D}{2}^2)\cdot D

  1. Now, let's define a new variable bigCones, whose value is 13π(D2)2D\frac{1}{3}\pi(\frac{D}{2})^2\cdot D

  2. Then, define another intermediate variable shape, whose value is woodbigCones\text{wood}-\text{bigCones}

  3. Last and finally, define the last variable cylinder to represent the volume of the inner cylinder, whose value is shape32\text{shape}\cdot \frac{3}{2}.

  4. Now, our d=2r=2cylinder2π3d=2\cdot r=2\cdot\sqrt[3]{\frac{\text{cylinder}}{2\pi}}

Code

https://github.com/mendax1234/Coding-Problems/blob/main/kattis/beavergnaw/beavergnaw.c

Last updated