I. Shell Game

Codeforces
IDCF10079I
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Bob has discovered a new quality in himself — he likes to trick people a lot! In particular, Bob wants to try his tricking skills in the shell game. The shell game involves three identical cups and a single ball. In the beginning the host (that's Bob!) puts the cups upside down and places the ball inside one of the cups. Then he shuffles the cups and the player has to guess where the ball is. The host then lifts that cup, revealing whether the ball was inside or not. The player wins if he makes a correct guess, otherwise the host wins. The form of each cup is a sliced cone. Formally, the base of the cup is a circle with radius r, and the opening of the cup is a circle with radius R. The height of the cup is equal to h. A ball for the shell game is simply a sphere. What the player is not going to know is that Bob smeared the inner surface of each cup with glue, resulting in the cup holding the ball when Bob lifts it up — so the player will never win! However, the ball will stick only if it touches the inner surface of a cup. For this reason Bob wants to get the largest possible ball that fits inside the cup when the cup is placed upside down on the table. Bob has already found three identical cups in his grandmother's locker — now he only has to buy a ball of the required size so that he may start playing the shell game. Help Bob and calculate the largest size of such a ball! The first line contains three space-separated integers r, R and h, the radii of the base and the opening, and the height of the cup (1 ≤ r < R ≤ 104, 1 ≤ h ≤ 104). Output a single number — the radius of the largest ball that can fit in the cup. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6. ## Input The first line contains three space-separated integers r, R and h, the radii of the base and the opening, and the height of the cup (1 ≤ r < R ≤ 104, 1 ≤ h ≤ 104). ## Output Output a single number — the radius of the largest ball that can fit in the cup. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6. [samples]
**Definitions** Let $ r, R, h \in \mathbb{R}^+ $ be the base radius, top radius, and height of a frustum-shaped cup, with $ 1 \leq r < R \leq 10^4 $ and $ 1 \leq h \leq 10^4 $. **Objective** Find the radius $ \rho $ of the largest sphere that can fit inside the frustum when placed upside down (i.e., with the larger circle $ R $ at the bottom and smaller circle $ r $ at the top), such that the sphere is tangent to the inner lateral surface and the base. **Geometric Constraint** The sphere is inscribed in the frustum, touching: - The conical lateral surface, - The circular base of radius $ R $. The largest such sphere is tangent to the frustum’s lateral side and rests on the base. The problem reduces to finding the radius of the incircle of the isosceles trapezoid cross-section through the axis of the frustum, inscribed in the right triangle formed by extending the frustum to a full cone. Let the full cone have height $ H $ and base radius $ R $. The frustum is a slice of this cone at height $ H - h $, leaving a smaller cone of height $ H - h $ and base radius $ r $. By similar triangles: $$ \frac{r}{R} = \frac{H - h}{H} \quad \Rightarrow \quad H = \frac{hR}{R - r} $$ The inscribed sphere of radius $ \rho $ touches the lateral side and the base. Consider the right triangle formed by the axis, the radius $ R $, and the slant side. The inscribed circle in this triangle (tangent to the base and the hypotenuse) has radius: $$ \rho = \frac{R \cdot (H - h)}{\sqrt{R^2 + H^2} + R} $$ But since the sphere must fit entirely within the frustum and touch the lateral wall and the base, we use the standard formula for the radius of the largest sphere inscribed in a frustum of a cone, resting on the larger base: $$ \rho = \frac{r + R}{2} \cdot \frac{h}{\sqrt{(R - r)^2 + h^2} + \frac{R + r}{2}} $$ Actually, the correct and standard derivation: Consider the 2D cross-section: an isosceles trapezoid with bases $ 2R $ and $ 2r $, height $ h $. The largest circle inscribed in this trapezoid (touching both non-parallel sides and the longer base) has radius: Let $ \theta $ be the angle between the slant side and the vertical. Then: $$ \tan \theta = \frac{R - r}{h} $$ The center of the sphere lies along the central axis at height $ \rho $ above the base. The distance from the center to the slant side must be $ \rho $. The perpendicular distance from the axis to the slant side at height $ y $ is $ R - y \cdot \frac{R - r}{h} $. At height $ \rho $, the horizontal distance from axis to wall is $ R - \rho \cdot \frac{R - r}{h} $. This must equal $ \rho $, because the sphere touches the wall: $$ R - \rho \cdot \frac{R - r}{h} = \rho $$ Solve for $ \rho $: $$ R = \rho \left(1 + \frac{R - r}{h}\right) \quad \Rightarrow \quad \rho = \frac{R}{1 + \frac{R - r}{h}} = \frac{R h}{h + R - r} $$ Wait — this is incorrect because the sphere touches the *lateral side* and the *base*, but the horizontal distance from axis to wall at height $ \rho $ is not simply $ R - \rho \cdot \frac{R - r}{h} $ — that’s the radius of the frustum at that height, and the sphere’s center is at height $ \rho $, so the horizontal distance from center to wall is $ R - \rho \cdot \frac{R - r}{h} $, and this must equal the radius of the sphere $ \rho $, since the sphere is tangent to the wall. So: $$ R - \rho \cdot \frac{R - r}{h} = \rho \Rightarrow R = \rho \left(1 + \frac{R - r}{h}\right) \Rightarrow \rho = \frac{R}{1 + \frac{R - r}{h}} = \frac{R h}{h + R - r} $$ But this gives a sphere that touches the lateral side and the base — and since the cup is upside down, the base is the large circle $ R $, and the top is small $ r $. So the sphere rests on the large base and touches the sloped side. Is this the maximal possible? Yes, because if it were larger, it would protrude above the frustum or not fit within the narrowing walls. **Final Formula** $$ \rho = \frac{R h}{h + R - r} $$ But wait — this formula gives a sphere that touches the lateral side and the base, but is it entirely contained? Let’s verify: at the top of the sphere (height $ 2\rho $), the radius of the frustum is $ R - 2\rho \cdot \frac{R - r}{h} $. We must ensure that this is $ \geq 0 $, and that the sphere doesn’t intersect the top rim. But the sphere’s top is at height $ 2\rho $, and the frustum’s radius at that height is $ R - 2\rho \cdot \frac{R - r}{h} $. The sphere has radius $ \rho $, so at height $ 2\rho $, the sphere’s horizontal extent is 0 (it’s the top point). So as long as the frustum’s radius at height $ 2\rho $ is $ \geq 0 $, it’s fine. But we don’t require the sphere to touch the top — only the base and the side. So the formula is correct. Actually, the standard known result for the largest sphere inscribed in a frustum (resting on the larger base) is: $$ \rho = \frac{r R + \sqrt{r R (r R + h^2)}}{r + R + \sqrt{(R - r)^2 + h^2}} $$ No — simpler and correct derivation: The sphere touches the conical surface. The cone’s side has slope $ m = \frac{R - r}{h} $. The distance from the center of the sphere (at $ (0, \rho) $) to the slant side must be $ \rho $. The slant side is a line from $ (R, 0) $ to $ (r, h) $. The equation of this line: Parametrize: from point $ (R, 0) $ to $ (r, h) $. The direction vector is $ (r - R, h) $. The line equation: $$ \frac{y - 0}{x - R} = \frac{h}{r - R} \Rightarrow y = \frac{h}{r - R}(x - R) $$ Rewrite: $$ \frac{h}{R - r}(R - x) = y \quad \text{(since } r - R = -(R - r)\text{)} $$ So: $$ y = \frac{h}{R - r}(R - x) $$ The distance from point $ (0, \rho) $ to this line must be $ \rho $. General distance from point $ (x_0, y_0) $ to line $ ax + by + c = 0 $: Write line as: $$ \frac{h}{R - r} x + y - \frac{h R}{R - r} = 0 \Rightarrow h x + (R - r) y - h R = 0 $$ So $ a = h $, $ b = R - r $, $ c = -h R $ Distance from $ (0, \rho) $: $$ \frac{|h \cdot 0 + (R - r)\rho - h R|}{\sqrt{h^2 + (R - r)^2}} = \rho $$ So: $$ \frac{|(R - r)\rho - h R|}{\sqrt{h^2 + (R - r)^2}} = \rho $$ Since $ (R - r)\rho - h R < 0 $ (because $ \rho < R $ and $ h R $ is large), we drop absolute value with sign change: $$ \frac{h R - (R - r)\rho}{\sqrt{h^2 + (R - r)^2}} = \rho $$ Multiply both sides: $$ h R - (R - r)\rho = \rho \sqrt{h^2 + (R - r)^2} $$ Bring terms with $ \rho $ to one side: $$ h R = \rho \left( (R - r) + \sqrt{h^2 + (R - r)^2} \right) $$ Therefore: $$ \boxed{ \rho = \frac{h R}{(R - r) + \sqrt{h^2 + (R - r)^2}} } $$ This is the correct formula. **Final Formal Statement** **Definitions** Let $ r, R, h \in \mathbb{R}^+ $ satisfy $ 1 \leq r < R \leq 10^4 $ and $ 1 \leq h \leq 10^4 $. The cup is a frustum of a cone with base radius $ R $, top radius $ r $, and height $ h $, oriented with the larger base on the table. **Objective** Find the radius $ \rho $ of the largest sphere that fits inside the frustum and is tangent to its lateral surface and base: $$ \rho = \frac{h R}{(R - r) + \sqrt{h^2 + (R - r)^2}} $$
API Response (JSON)
{
  "problem": {
    "name": "I. Shell Game",
    "description": {
      "content": "Bob has discovered a new quality in himself — he likes to trick people a lot! In particular, Bob wants to try his tricking skills in the shell game. The shell game involves three identical cups and a",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10079I"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Bob has discovered a new quality in himself — he likes to trick people a lot! In particular, Bob wants to try his tricking skills in the shell game.\n\nThe shell game involves three identical cups and a...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ r, R, h \\in \\mathbb{R}^+ $ be the base radius, top radius, and height of a frustum-shaped cup, with $ 1 \\leq r < R \\leq 10^4 $ and $ 1 \\leq h \\leq 10^4 $.  \n\n**Objective**  \nFi...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments