176. Catapult

Codeforces
IDCF10269176
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You're testing out a catapult that you built for POE class, and you're trying to get it to launch an eraser over a wall. The catapult launches the eraser $a$ meters away from the wall, and you're trying to get the catapult to hit a target $b$ feet above the ground, and $c$ meters away from the wall in the exact opposite direction. The wall is $d$ meters high, and it is very thin (assume it has no thickness). Given this information, figure out the minimum possible maximum height of the eraser, such that the eraser still clears the wall. In other words, among all eraser trajectories that hit the target and successfully clear the wall, find the lowest possible maximum height of the eraser. Assume that you launch the device in a vacuum (i.e. there is no air resistance). The only line of input contains 4 space-separated positive integers: $a$, $b$, $c$, and $d$, as described above. $b$ is guaranteed to be less than $d$. Output a single positive integer $h$: the maximum height of the eraser, if you launch it so that it hits the target and clears the wall, and has the minimum possible maximum height. You don't need to use any physics equations to solve this problem. You can solve it using only algebra. Also, your answers don't have to be exactly equal to ours. As long as they're within a few decimal places, your solution will be judged as correct. ## Input The only line of input contains 4 space-separated positive integers: $a$, $b$, $c$, and $d$, as described above. $b$ is guaranteed to be less than $d$. ## Output Output a single positive integer $h$: the maximum height of the eraser, if you launch it so that it hits the target and clears the wall, and has the minimum possible maximum height. [samples] ## Note You don't need to use any physics equations to solve this problem. You can solve it using only algebra.Also, your answers don't have to be exactly equal to ours. As long as they're within a few decimal places, your solution will be judged as correct.
Let $ a, c, d \in \mathbb{R}^+ $ be horizontal distances (in meters), and $ b, d \in \mathbb{R}^+ $ be vertical heights (in feet, but unit consistency assumed), with $ b < d $. Define the launch point at $ (0, 0) $, the wall at $ x = a $ with height $ d $, and the target at $ x = a + c $ with height $ b $. Assume the eraser follows a parabolic trajectory: $ y(x) = px(1 - \frac{x}{a+c}) $, or equivalently, a quadratic passing through $ (0,0) $ and $ (a+c, b) $. We seek the **minimum possible maximum height** $ h $ of such a parabola that satisfies $ y(a) \geq d $. Let the trajectory be: $ y(x) = kx(a + c - x) $, normalized to pass through $ (a+c, b) $: Then $ b = k(a+c)c \Rightarrow k = \frac{b}{c(a+c)} $. So: $ y(x) = \frac{b}{c(a+c)} x(a + c - x) $ The maximum height occurs at vertex $ x = \frac{a+c}{2} $: $ h = y\left( \frac{a+c}{2} \right) = \frac{b}{c(a+c)} \cdot \frac{a+c}{2} \cdot \frac{a+c}{2} = \frac{b(a+c)}{4c} $ But we must enforce $ y(a) \geq d $: $ y(a) = \frac{b}{c(a+c)} \cdot a \cdot (a + c - a) = \frac{b}{c(a+c)} \cdot a \cdot c = \frac{ab}{a+c} \geq d $ This constraint $ \frac{ab}{a+c} \geq d $ is **not** satisfied in general (and is given that $ b < d $, so likely violated). Thus, the **unconstrained** parabola through $ (0,0) $ and $ (a+c, b) $ does **not** clear the wall. We must find the **lowest** parabola passing through $ (0,0) $ and $ (a+c, b) $, and tangent to the line $ y = d $ at $ x = a $ — i.e., the minimal maximum height trajectory that **just clears** the wall. So impose: 1. $ y(0) = 0 $ 2. $ y(a+c) = b $ 3. $ y(a) = d $ 4. $ y'(a) = 0 $ (tangent at wall — minimal max height) Let $ y(x) = px^2 + qx $ Conditions: - $ y(0) = 0 $ → satisfied - $ y(a+c) = p(a+c)^2 + q(a+c) = b $ - $ y(a) = pa^2 + qa = d $ - $ y'(x) = 2px + q \Rightarrow y'(a) = 2pa + q = 0 \Rightarrow q = -2pa $ Substitute $ q = -2pa $ into $ y(a) = d $: $ pa^2 - 2pa^2 = d \Rightarrow -pa^2 = d \Rightarrow p = -\frac{d}{a^2} $ Then $ q = -2p a = \frac{2d}{a} $ Now plug into $ y(a+c) = b $: $ p(a+c)^2 + q(a+c) = b $ $ -\frac{d}{a^2}(a+c)^2 + \frac{2d}{a}(a+c) = b $ Factor $ d(a+c)/a $: $ d(a+c) \left( -\frac{a+c}{a^2} + \frac{2}{a} \right) = b $ $ d(a+c) \left( \frac{ - (a+c) + 2a }{a^2} \right) = b $ $ d(a+c) \left( \frac{ a - c }{a^2} \right) = b $ So: $ d(a+c)(a - c) = a^2 b $ → $ d(a^2 - c^2) = a^2 b $ But this is a **constraint** that must hold — yet in general it does not. So we **cannot** assume tangency unless this holds. But we are told: “find the minimum possible maximum height such that the eraser clears the wall and hits the target”. So we must find the **parabola** through $ (0,0) $ and $ (a+c, b) $, with **minimum apex height**, subject to $ y(a) \geq d $. Let the general parabola: $ y(x) = kx(a+c - x) $, as before → apex at $ x = \frac{a+c}{2} $, height $ h = \frac{k(a+c)^2}{4} $ Constraint: $ y(a) = k a c \geq d \Rightarrow k \geq \frac{d}{ac} $ Minimize $ h = \frac{k(a+c)^2}{4} \Rightarrow $ minimize $ k $, so set $ k = \frac{d}{ac} $ Then: $ h = \frac{d}{ac} \cdot \frac{(a+c)^2}{4} = \frac{d(a+c)^2}{4ac} $ **Thus, the minimal possible maximum height is:** $$ \boxed{h = \frac{d(a + c)^2}{4ac}} $$
API Response (JSON)
{
  "problem": {
    "name": "176. Catapult",
    "description": {
      "content": "You're testing out a catapult that you built for POE class, and you're trying to get it to launch an eraser over a wall. The catapult launches the eraser $a$ meters away from the wall, and you're try",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269176"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You're testing out a catapult that you built for POE class, and you're trying to get it to launch an eraser over a wall.\n\nThe catapult launches the eraser $a$ meters away from the wall, and you're try...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ a, c, d \\in \\mathbb{R}^+ $ be horizontal distances (in meters), and $ b, d \\in \\mathbb{R}^+ $ be vertical heights (in feet, but unit consistency assumed), with $ b < d $.\n\nDefine the launch poin...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments