Problem Summary

A firecracker explodes at height

$$h=100\ \text{m}$$

above the ground. Every tiny fragment leaves the explosion point with the same speed

$$v=20\ \text{m/s}$$

but in an arbitrary direction. Gravity is constant:

$$g=9.81\ \text{m/s}^2.$$

Ignoring air resistance, we must find the volume of the whole region visited by the fragments before they hit the ground.

Mathematical Approach

1) Rotational symmetry reduces the problem to a 2D cross-section.

Because the launch speed is the same in every direction, the reachable region is symmetric around the vertical axis through the explosion point. So it is enough to work in cylindrical coordinates:

$$r=\sqrt{x^2+z^2},\qquad y=\text{height above ground}.$$

Once we know the boundary curve \(y(r)\) in the \((r,y)\)-plane, the full 3D region is obtained by revolving that curve around the \(y\)-axis.

2) One projectile trajectory.

Let \(\theta\) be the launch angle above the horizontal. Then the fragment satisfies

$$r(t)=v\cos\theta\; t,$$

$$y(t)=h+v\sin\theta\; t-\frac12gt^2.$$

Eliminating \(t\) using \(t=r/(v\cos\theta)\) gives the familiar projectile parabola

$$y(r,\theta)=h+r\tan\theta-\frac{gr^2}{2v^2\cos^2\theta}.$$

3) Rewrite with \(u=\tan\theta\).

Since

$$\frac1{\cos^2\theta}=1+\tan^2\theta=1+u^2,$$

we can write

$$y(r,u)=h+ru-\frac{gr^2}{2v^2}(1+u^2).$$

For fixed \(r\), this is a concave quadratic polynomial in \(u\). Therefore its maximum over all launch angles is found by differentiating with respect to \(u\).

4) The envelope of all trajectories.

Differentiate:

$$\frac{\partial y}{\partial u}=r-\frac{gr^2}{v^2}u.$$

Setting this to zero yields the maximizing slope

$$u=\tan\theta=\frac{v^2}{gr}.$$

Substituting back gives the upper envelope

$$y_{\max}(r)=h+\frac{v^2}{2g}-\frac{gr^2}{2v^2}.$$

It is convenient to abbreviate

$$a=h+\frac{v^2}{2g},\qquad b=\frac{g}{2v^2},$$

so that

$$y_{\max}(r)=a-br^2.$$

This is the paraboloid boundary used by the code.

5) Why the whole region below the envelope is actually filled.

For fixed \(r\), the value \(y(r,u)\) depends continuously on \(u\). One choice of \(u\) makes the fragment hit the ground exactly at that radius, so \(y=0\) is achievable there. Another choice gives the maximal height \(y_{\max}(r)\). By continuity, every intermediate height between \(0\) and \(y_{\max}(r)\) is also reached by some launch angle.

So the cross-section at radius \(r\) is not just a boundary point: it is the full vertical interval

$$0\le y\le y_{\max}(r).$$

6) Where does the region stop?

The outer radius is where the envelope reaches ground level:

$$a-br_{\max}^2=0,$$

hence

$$r_{\max}^2=\frac{a}{b}.$$

With the numerical constants,

$$a\approx120.3873598369,\qquad b=0.0122625,\qquad r_{\max}\approx99.0834077898.$$

7) Volume by washers.

At height \(y\), the cross-section is a disk of radius \(r(y)\), where

$$r(y)^2=\frac{a-y}{b}\qquad (0\le y\le a).$$

Therefore

$$V=\pi\int_0^a r(y)^2\,dy=\pi\int_0^a \frac{a-y}{b}\,dy.$$

Evaluating the integral gives

$$V=\frac{\pi a^2}{2b}.$$

8) Equivalent shell integral.

The same answer appears if we integrate cylindrical shells:

$$V=2\pi\int_0^{r_{\max}} r\,y_{\max}(r)\,dr$$

$$=2\pi\int_0^{r_{\max}} r(a-br^2)\,dr=\frac{\pi a^2}{2b}.$$

This is exactly the comment embedded in the C++ solution.

9) Final closed form.

Substituting the definitions of \(a\) and \(b\), we obtain

$$V=\pi\frac{v^2}{g}\left(h+\frac{v^2}{2g}\right)^2.$$

This is why the program is only a direct evaluation of a closed formula.

10) Useful checkpoint: \(h=0\).

If the explosion happens on the ground, then

$$a=\frac{v^2}{2g},\qquad b=\frac{g}{2v^2},$$

so

$$V=\frac{\pi a^2}{2b}=\frac{\pi v^6}{4g^3}.$$

This is the exact checkpoint used in the source code.

Algorithm

1) Read \(h\), \(v\), and \(g\).

2) Compute

$$a=h+\frac{v^2}{2g},\qquad b=\frac{g}{2v^2}.$$

3) Return

$$V=\frac{\pi a^2}{2b}.$$

4) Print the result rounded to four decimal places.

Complexity Analysis

Everything is closed form, so the computation costs

$$O(1)$$

time and

$$O(1)$$

memory.

Checks And Final Result

The code checks the special case

$$h=0\implies V=\frac{\pi v^6}{4g^3}.$$

For the actual problem data \((h,v,g)=(100,20,9.81)\), the computed volume is

$$1856532.8455.$$

Further Reading

  1. Problem page: https://projecteuler.net/problem=317
  2. Projectile motion: https://en.wikipedia.org/wiki/Projectile_motion
  3. Solid of revolution: https://en.wikipedia.org/wiki/Solid_of_revolution

Problemzusammenfassung

Ein Feuerwerkskoerper explodiert in der Hoehe

$$h=100\ \text{m}$$

und schleudert unzaehlige kleine Fragmente mit derselben Anfangsgeschwindigkeit

$$v=20\ \text{m/s}$$

in alle Richtungen. Bei konstanter Schwerkraft

$$g=9.81\ \text{m/s}^2$$

soll das Volumen der gesamten durchlaufenen Region berechnet werden.

Mathematischer Ansatz

1) Rotationssymmetrie.

Wegen der isotropen Startgeschwindigkeit ist die Region um die Vertikalachse rotationssymmetrisch. Es genuegt also, im \((r,y)\)-Schnitt zu arbeiten, mit

$$r=\sqrt{x^2+z^2}.$$

2) Eine einzelne Wurfparabel.

Fuer Startwinkel \(\theta\) ueber dem Horizont gilt

$$r(t)=v\cos\theta\; t,$$

$$y(t)=h+v\sin\theta\; t-\frac12gt^2.$$

Nach Eliminieren von \(t\) erhaelt man

$$y(r,\theta)=h+r\tan\theta-\frac{gr^2}{2v^2\cos^2\theta}.$$

3) Umformung mit \(u=\tan\theta\).

Mit \(1/\cos^2\theta=1+u^2\) wird daraus

$$y(r,u)=h+ru-\frac{gr^2}{2v^2}(1+u^2).$$

Fuer festes \(r\) ist das eine konkave Quadratik in \(u\), also leicht maximierbar.

4) Huellkurve aller Bahnen.

Aus

$$\frac{\partial y}{\partial u}=r-\frac{gr^2}{v^2}u=0$$

folgt

$$u=\frac{v^2}{gr}.$$

Eingesetzt ergibt das

$$y_{\max}(r)=h+\frac{v^2}{2g}-\frac{gr^2}{2v^2}=a-br^2,$$

mit

$$a=h+\frac{v^2}{2g},\qquad b=\frac{g}{2v^2}.$$

5) Warum der gesamte Bereich unter der Huellkurve gefuellt ist.

Fuer festes \(r\) ist \(y(r,u)\) stetig in \(u\). Ein Winkel trifft den Boden genau bei diesem Radius, also ist \(y=0\) erreichbar. Ein anderer Winkel liefert die maximale Hoehe \(y_{\max}(r)\). Daher werden durch Stetigkeit alle Zwischenhoehen zwischen \(0\) und \(y_{\max}(r)\) ebenfalls getroffen.

6) Aeusserer Radius.

Die Region endet bei

$$a-br_{\max}^2=0,$$

also

$$r_{\max}^2=\frac{a}{b}.$$

7) Volumenintegral.

Aus

$$r(y)^2=\frac{a-y}{b}\qquad (0\le y\le a)$$

folgt per Scheibenmethode

$$V=\pi\int_0^a r(y)^2\,dy=\pi\int_0^a \frac{a-y}{b}\,dy=\frac{\pi a^2}{2b}.$$

Gleichwertig ist auch die Schalenmethode

$$V=2\pi\int_0^{r_{\max}}r(a-br^2)\,dr.$$

8) Endformel.

Damit erhalten wir

$$V=\pi\frac{v^2}{g}\left(h+\frac{v^2}{2g}\right)^2.$$

9) Kontrollfall \(h=0\).

Dann reduziert sich die Formel zu

$$V=\frac{\pi v^6}{4g^3},$$

genau wie im Checkpoint des Programms.

Algorithmus

1) Werte \(a\) und \(b\) berechnen.

2) Mit

$$V=\frac{\pi a^2}{2b}$$

das Volumen direkt auswerten.

3) Auf vier Nachkommastellen runden.

Komplexitaetsanalyse

Nur eine geschlossene Formel, also \(O(1)\) Zeit und \(O(1)\) Speicher.

Kontrollen Und Endergebnis

Der Code prueft den Spezialfall

$$h=0\implies V=\frac{\pi v^6}{4g^3}.$$

Fuer \((h,v,g)=(100,20,9.81)\) ergibt sich

$$1856532.8455.$$

Weiterfuehrende Hinweise

  1. Problem: https://projecteuler.net/problem=317
  2. Schiefer Wurf: https://de.wikipedia.org/wiki/Schiefer_Wurf
  3. Rotationskoerper: https://de.wikipedia.org/wiki/Rotationskörper

Problem Özeti

Yerden

$$h=100\ \text{m}$$

yuksekte patlayan bir fisek, cok sayida parcayi ayni baslangic hiziyla

$$v=20\ \text{m/s}$$

her yone savuruyor. Hava direnci yok ve yercekimi sabit:

$$g=9.81\ \text{m/s}^2.$$

Parcalar yere dusmeden once uzayda taranan bolgenin hacmi isteniyor.

Matematiksel Yaklaşım

1) Donel simetri problemi 2B kesite indirir.

Patlama noktasindan cikis hizi her yatay yonde ayni oldugu icin bolge dikey eksen etrafinda donel simetriktir. Bu yuzden yalnizca

$$r=\sqrt{x^2+z^2},\qquad y=\text{yerden yukseklik}$$

koordinatlariyla calismak yeterlidir.

2) Tek bir parcanin yorlugu.

Yatay duzleme gore atis acisi \(\theta\) olsun. O zaman

$$r(t)=v\cos\theta\; t,$$

$$y(t)=h+v\sin\theta\; t-\frac12gt^2.$$

\(t=r/(v\cos\theta)\) yazinca standart yorge denklemi gelir:

$$y(r,\theta)=h+r\tan\theta-\frac{gr^2}{2v^2\cos^2\theta}.$$

3) \(\tan\theta\) ile yazmak neden faydali?

\(u=\tan\theta\) dersek ve \(1/\cos^2\theta=1+u^2\) kullanirsak

$$y(r,u)=h+ru-\frac{gr^2}{2v^2}(1+u^2)$$

elde edilir. Sabit \(r\) icin bu, \(u\) degiskeninde asagi bakan bir parabol oldugu icin maksimum yuksekligi turevle dogrudan bulabiliriz.

4) Tum yorgelerin zarfi.

Turev

$$\frac{\partial y}{\partial u}=r-\frac{gr^2}{v^2}u$$

olur. Sifira esitlenince

$$u=\frac{v^2}{gr}$$

gelir ve bunu yerine koyunca ust sinir

$$y_{\max}(r)=h+\frac{v^2}{2g}-\frac{gr^2}{2v^2}$$

seklinde bulunur. Kisaca

$$a=h+\frac{v^2}{2g},\qquad b=\frac{g}{2v^2},\qquad y_{\max}(r)=a-br^2.$$

Yani sinir bir paraboloiddir.

5) Neden yalnizca zarf degil, zarfin alti da dolu?

Sabit \(r\) icin \(y(r,u)\), \(u\)'ya gore sureklidir. Uygun bir aci parcayi tam o yaricapta yere indirir, yani \(y=0\) elde edilir. Baska bir aci ise \(y_{\max}(r)\)'yi verir. Sureklilikten dolayi aradaki butun yukseklikler de bir aci icin gerceklesir. Demek ki kesit, sadece tek bir nokta degil,

$$0\le y\le y_{\max}(r)$$

araligidir.

6) Bolge nerede biter?

Dis yaricap, zarfin yere degdigi yerde biter:

$$a-br_{\max}^2=0\qquad\Longrightarrow\qquad r_{\max}^2=\frac{a}{b}.$$

Sayisal olarak

$$a\approx120.3873598369,\qquad b=0.0122625,\qquad r_{\max}\approx99.0834077898.$$

7) Hacim integrali.

Yukseklik \(y\) sabitken kesit yaricapi

$$r(y)^2=\frac{a-y}{b}\qquad (0\le y\le a)$$

olur. Disk yontemi ile

$$V=\pi\int_0^a r(y)^2\,dy=\pi\int_0^a \frac{a-y}{b}\,dy=\frac{\pi a^2}{2b}.$$

Ayni sonuc silindirik kabuklarla da elde edilir:

$$V=2\pi\int_0^{r_{\max}} r(a-br^2)\,dr.$$

8) Son kapali form.

\(a\) ve \(b\)'yi geri yerine yazinca

$$V=\pi\frac{v^2}{g}\left(h+\frac{v^2}{2g}\right)^2$$

elde edilir. Kod da tam olarak bu formulu sayisal olarak degerlendirir.

9) Faydalı checkpoint: \(h=0\).

Patlama yerde olsaydi

$$V=\frac{\pi v^6}{4g^3}$$

olurdu. Kaynak kodun yaptigi kontrol tam budur.

Algoritma

1) \(a\) ve \(b\) sabitlerini hesapla.

2) Kapali formulu uygula:

$$V=\frac{\pi a^2}{2b}.$$

3) Sonucu dort ondaliga yuvarla.

Karmaşıklık Analizi

Hesap tamamen kapali form oldugu icin zaman

$$O(1)$$

ve bellek

$$O(1)$$

olur.

Kontroller Ve Nihai Sonuc

Kod once

$$h=0\implies V=\frac{\pi v^6}{4g^3}$$

kontrolunu yapar. Problemde verilen \((h,v,g)=(100,20,9.81)\) degerleri icin son cevap

$$1856532.8455$$

olarak bulunur.

Ileri Okuma

  1. Problem metni: https://projecteuler.net/problem=317
  2. Egik atis: https://tr.wikipedia.org/wiki/Eğik_atış
  3. Donel cisim: https://tr.wikipedia.org/wiki/Dönel_cisim

Resumen del Problema

Un petardo explota a la altura

$$h=100\ \text{m}$$

y lanza fragmentos con velocidad inicial comun

$$v=20\ \text{m/s}$$

en todas las direcciones. Sin resistencia del aire y con gravedad constante

$$g=9.81\ \text{m/s}^2,$$

hay que hallar el volumen total de la region recorrida antes de tocar el suelo.

Enfoque Matematico

1) Simetria de revolucion.

La situacion es simetrica alrededor del eje vertical del punto de explosion. Por eso basta estudiar la seccion en coordenadas \((r,y)\), donde

$$r=\sqrt{x^2+z^2}.$$

2) Una trayectoria individual.

Si \(\theta\) es el angulo sobre la horizontal, entonces

$$r(t)=v\cos\theta\; t,$$

$$y(t)=h+v\sin\theta\; t-\frac12gt^2.$$

Eliminando \(t\):

$$y(r,\theta)=h+r\tan\theta-\frac{gr^2}{2v^2\cos^2\theta}.$$

3) Maximizar con \(u=\tan\theta\).

Usando \(1/\cos^2\theta=1+u^2\), queda

$$y(r,u)=h+ru-\frac{gr^2}{2v^2}(1+u^2).$$

Para radio fijo \(r\), esto es una cuadratica concava en \(u\).

4) Envolvente superior.

Derivando y anulando:

$$\frac{\partial y}{\partial u}=r-\frac{gr^2}{v^2}u=0,$$

de donde

$$u=\frac{v^2}{gr}.$$

Sustituyendo:

$$y_{\max}(r)=h+\frac{v^2}{2g}-\frac{gr^2}{2v^2}=a-br^2,$$

con

$$a=h+\frac{v^2}{2g},\qquad b=\frac{g}{2v^2}.$$

5) Por que toda la parte inferior tambien pertenece a la region.

Para un radio fijo, \(y(r,u)\) cambia continuamente con el angulo. Un cierto angulo hace que el fragmento llegue al suelo justo en ese radio, o sea \(y=0\). Otro angulo da la altura maxima \(y_{\max}(r)\). Por continuidad, todos los valores intermedios aparecen tambien.

6) Radio extremo.

La frontera toca el suelo cuando

$$a-br_{\max}^2=0,$$

asi que

$$r_{\max}^2=\frac{a}{b}.$$

7) Integral de volumen.

Como

$$r(y)^2=\frac{a-y}{b}\qquad (0\le y\le a),$$

la formula por discos da

$$V=\pi\int_0^a r(y)^2\,dy=\frac{\pi a^2}{2b}.$$

La misma respuesta sale con capas cilindricas:

$$V=2\pi\int_0^{r_{\max}} r(a-br^2)\,dr.$$

8) Forma cerrada final.

Al reemplazar \(a\) y \(b\):

$$V=\pi\frac{v^2}{g}\left(h+\frac{v^2}{2g}\right)^2.$$

9) Punto de control \(h=0\).

Entonces

$$V=\frac{\pi v^6}{4g^3},$$

exactamente la comprobacion del codigo.

Algoritmo

1) Calcular \(a\) y \(b\).

2) Evaluar

$$V=\frac{\pi a^2}{2b}.$$

3) Redondear a cuatro decimales.

Complejidad

Solo hay una formula cerrada, asi que el coste es \(O(1)\) en tiempo y \(O(1)\) en memoria.

Comprobaciones Y Resultado Final

El programa verifica el caso

$$h=0\implies V=\frac{\pi v^6}{4g^3}.$$

Para \((h,v,g)=(100,20,9.81)\), el resultado final es

$$1856532.8455.$$

Lecturas

  1. Problema: https://projecteuler.net/problem=317
  2. Tiro parabolico: https://es.wikipedia.org/wiki/Tiro_parabólico
  3. Solido de revolucion: https://es.wikipedia.org/wiki/Sólido_de_revolución

问题概述

烟花在

$$h=100\ \text{m}$$

高处爆炸,所有碎片都以相同初速度

$$v=20\ \text{m/s}$$

向各个方向飞出。忽略空气阻力,重力加速度为

$$g=9.81\ \text{m/s}^2.$$

要求这些碎片在落地前扫过的整个空间区域体积。

数学方法

1)轴对称,把三维问题降到二维。

由于初速度大小在所有方向都相同,区域绕竖直轴旋转对称。于是只需要研究 \((r,y)\) 平面中的截面,其中

$$r=\sqrt{x^2+z^2}.$$

2)单条抛体轨迹。

若发射角为 \(\theta\),则

$$r(t)=v\cos\theta\; t,$$

$$y(t)=h+v\sin\theta\; t-\frac12gt^2.$$

消去 \(t\) 得到

$$y(r,\theta)=h+r\tan\theta-\frac{gr^2}{2v^2\cos^2\theta}.$$

3)令 \(u=\tan\theta\)。

利用 \(1/\cos^2\theta=1+u^2\),有

$$y(r,u)=h+ru-\frac{gr^2}{2v^2}(1+u^2).$$

对固定的 \(r\),这是关于 \(u\) 的开口向下二次函数,所以最大值可以直接求导得到。

4)所有轨迹的包络。

求导并令其为零:

$$\frac{\partial y}{\partial u}=r-\frac{gr^2}{v^2}u=0,$$

$$u=\frac{v^2}{gr}.$$

代回得到上包络

$$y_{\max}(r)=h+\frac{v^2}{2g}-\frac{gr^2}{2v^2}=a-br^2,$$

其中

$$a=h+\frac{v^2}{2g},\qquad b=\frac{g}{2v^2}.$$

5)为什么包络下面整块区域都被覆盖。

对固定 \(r\),函数 \(y(r,u)\) 随 \(u\) 连续变化。某个角度会让碎片恰好在这个半径落地,所以 \(y=0\) 可以达到;另一个角度给出最高点 \(y_{\max}(r)\)。由连续性可知,中间所有高度也都会被某个发射角经过。

6)最大半径。

包络与地面相交时满足

$$a-br_{\max}^2=0,$$

因此

$$r_{\max}^2=\frac{a}{b}.$$

7)体积积分。

对高度 \(y\),截面半径满足

$$r(y)^2=\frac{a-y}{b}\qquad (0\le y\le a).$$

于是用圆盘法

$$V=\pi\int_0^a r(y)^2\,dy=\frac{\pi a^2}{2b}.$$

也可以用柱壳法写成

$$V=2\pi\int_0^{r_{\max}} r(a-br^2)\,dr.$$

8)最终闭式。

代回 \(a,b\) 得

$$V=\pi\frac{v^2}{g}\left(h+\frac{v^2}{2g}\right)^2.$$

9)检查点 \(h=0\)。

此时公式退化为

$$V=\frac{\pi v^6}{4g^3},$$

这正是源码中的校验式。

算法

1) 计算 \(a\) 与 \(b\)。

2) 直接代入

$$V=\frac{\pi a^2}{2b}.$$

3) 输出四位小数。

复杂度分析

全程只是闭式代入,所以时间复杂度和空间复杂度都是

$$O(1).$$

校验与最终结果

程序先检查

$$h=0\implies V=\frac{\pi v^6}{4g^3}.$$

对题目参数 \((h,v,g)=(100,20,9.81)\),最终结果为

$$1856532.8455.$$

延伸阅读

  1. 题目页面: https://projecteuler.net/problem=317
  2. 抛体运动: https://zh.wikipedia.org/wiki/抛射運動
  3. 旋转体: https://zh.wikipedia.org/wiki/旋转体

Краткое описание

Фейерверк взрывается на высоте

$$h=100\ \text{м}$$

и выбрасывает осколки с одинаковой начальной скоростью

$$v=20\ \text{м/с}$$

во всех направлениях. Без сопротивления воздуха и при постоянной гравитации

$$g=9.81\ \text{м/с}^2$$

нужно найти объем области, через которую проходят осколки до падения на землю.

Математический подход

1) Осесимметрия.

Так как модуль начальной скорости одинаков во всех направлениях, область симметрична относительно вертикальной оси. Достаточно рассматривать сечение в координатах \((r,y)\), где

$$r=\sqrt{x^2+z^2}.$$

2) Одна траектория.

При угле запуска \(\theta\) над горизонтом

$$r(t)=v\cos\theta\; t,$$

$$y(t)=h+v\sin\theta\; t-\frac12gt^2.$$

После исключения \(t\):

$$y(r,\theta)=h+r\tan\theta-\frac{gr^2}{2v^2\cos^2\theta}.$$

3) Переход к \(u=\tan\theta\).

Используя \(1/\cos^2\theta=1+u^2\), получаем

$$y(r,u)=h+ru-\frac{gr^2}{2v^2}(1+u^2).$$

Для фиксированного \(r\) это вогнутая квадратичная функция по \(u\).

4) Огибающая всех траекторий.

Из условия максимума

$$\frac{\partial y}{\partial u}=r-\frac{gr^2}{v^2}u=0$$

следует

$$u=\frac{v^2}{gr}.$$

Подстановка дает

$$y_{\max}(r)=h+\frac{v^2}{2g}-\frac{gr^2}{2v^2}=a-br^2,$$

где

$$a=h+\frac{v^2}{2g},\qquad b=\frac{g}{2v^2}.$$

5) Почему заполняется вся область ниже огибающей.

При фиксированном \(r\) величина \(y(r,u)\) непрерывно зависит от \(u\). Один угол дает высоту \(0\) в этом радиусе, другой дает максимум \(y_{\max}(r)\). Значит, по непрерывности реализуются все промежуточные высоты между ними.

6) Внешний радиус.

Граница заканчивается там, где огибающая касается земли:

$$a-br_{\max}^2=0,\qquad r_{\max}^2=\frac{a}{b}.$$

7) Интеграл для объема.

Поскольку

$$r(y)^2=\frac{a-y}{b}\qquad (0\le y\le a),$$

по методу дисков получаем

$$V=\pi\int_0^a r(y)^2\,dy=\frac{\pi a^2}{2b}.$$

Равноценная форма через цилиндрические оболочки:

$$V=2\pi\int_0^{r_{\max}} r(a-br^2)\,dr.$$

8) Итоговая формула.

После подстановки \(a\) и \(b\):

$$V=\pi\frac{v^2}{g}\left(h+\frac{v^2}{2g}\right)^2.$$

9) Контрольный случай \(h=0\).

Тогда

$$V=\frac{\pi v^6}{4g^3},$$

что и проверяет программа.

Алгоритм

1) Вычислить \(a\) и \(b\).

2) Подставить их в

$$V=\frac{\pi a^2}{2b}.$$

3) Вывести ответ с четырьмя знаками после запятой.

Сложность

Используется только замкнутая формула, значит время и память равны \(O(1)\).

Проверки И Итоговый Ответ

Код проверяет случай

$$h=0\implies V=\frac{\pi v^6}{4g^3}.$$

Для \((h,v,g)=(100,20,9.81)\) получается

$$1856532.8455.$$

Дополнительные материалы

  1. Условие: https://projecteuler.net/problem=317
  2. Движение тела, брошенного под углом: https://ru.wikipedia.org/wiki/Тело,_брошенное_под_углом_к_горизонту
  3. Тело вращения: https://ru.wikipedia.org/wiki/Тело_вращения

ملخص المسألة

ينفجر جسم على ارتفاع

$$h=100\ \text{m}$$

فوق سطح الأرض، وتخرج الشظايا كلها بالسرعة الابتدائية نفسها

$$v=20\ \text{m/s}$$

في جميع الاتجاهات. نهمل مقاومة الهواء ونعتمد مجال جاذبية منتظماً

$$g=9.81\ \text{m/s}^2.$$

المطلوب هو حجم المنطقة الكاملة التي تمر بها الشظايا قبل أن تصل إلى الأرض.

المنهج الرياضي

1) التناظر الدوراني يختزل المسألة إلى مقطع ثنائي الأبعاد.

بما أن مقدار السرعة الابتدائية واحد في كل الاتجاهات، فالمنطقة متناظرة حول المحور الرأسي. لذلك يكفي أن نعمل في الإحداثيات

$$r=\sqrt{x^2+z^2},\qquad y=\text{الارتفاع عن الأرض}.$$

2) مسار مقذوف واحد.

إذا كانت زاوية الإطلاق فوق الأفق هي \(\theta\)، فإن

$$r(t)=v\cos\theta\; t,$$

$$y(t)=h+v\sin\theta\; t-\frac12gt^2.$$

وبحذف \(t\) نحصل على

$$y(r,\theta)=h+r\tan\theta-\frac{gr^2}{2v^2\cos^2\theta}.$$

3) نكتبها بدلالة \(u=\tan\theta\).

باستخدام \(1/\cos^2\theta=1+u^2\) نحصل على

$$y(r,u)=h+ru-\frac{gr^2}{2v^2}(1+u^2).$$

وبالنسبة إلى \(r\) ثابت، فهذا كثير حدود تربيعي مقعر في \(u\)، وبالتالي يمكن إيجاد قمته مباشرة.

4) غلاف جميع المسارات.

من

$$\frac{\partial y}{\partial u}=r-\frac{gr^2}{v^2}u=0$$

نستنتج

$$u=\frac{v^2}{gr}.$$

وبالتعويض نحصل على الغلاف العلوي

$$y_{\max}(r)=h+\frac{v^2}{2g}-\frac{gr^2}{2v^2}=a-br^2,$$

حيث

$$a=h+\frac{v^2}{2g},\qquad b=\frac{g}{2v^2}.$$

5) لماذا تكون المنطقة كلها تحت الغلاف ممتلئة فعلاً؟

عند تثبيت \(r\)، تتغير \(y(r,u)\) بشكل مستمر مع \(u\). توجد زاوية تجعل الشظية تلامس الأرض عند هذا نصف القطر، أي تحقق \(y=0\). وتوجد زاوية أخرى تحقق القيمة العظمى \(y_{\max}(r)\). وبالاستمرارية، تتحقق كل القيم المتوسطة بينهما أيضاً.

6) نصف القطر الأقصى.

تنتهي المنطقة عندما يلامس الغلاف الأرض:

$$a-br_{\max}^2=0,\qquad r_{\max}^2=\frac{a}{b}.$$

7) تكامل الحجم.

لأن

$$r(y)^2=\frac{a-y}{b}\qquad (0\le y\le a),$$

فإن طريقة الأقراص تعطي

$$V=\pi\int_0^a r(y)^2\,dy=\frac{\pi a^2}{2b}.$$

وبالمثل يمكن كتابته بطريقة الأغماد الأسطوانية:

$$V=2\pi\int_0^{r_{\max}} r(a-br^2)\,dr.$$

8) الصيغة المغلقة النهائية.

بعد التعويض عن \(a\) و\(b\):

$$V=\pi\frac{v^2}{g}\left(h+\frac{v^2}{2g}\right)^2.$$

9) نقطة تحقق مهمة: عندما \(h=0\).

حينها تختزل الصيغة إلى

$$V=\frac{\pi v^6}{4g^3},$$

وهذا هو التحقق الموجود في الشيفرة.

الخوارزمية

1) نحسب \(a\) و\(b\).

2) نقيّم مباشرة

$$V=\frac{\pi a^2}{2b}.$$

3) نطبع الجواب بعد التقريب إلى أربع منازل عشرية.

تحليل التعقيد

الحل كله بصيغة مغلقة، لذا الزمن والذاكرة كلاهما

$$O(1).$$

التحقق والنتيجة النهائية

يتحقق البرنامج من الحالة

$$h=0\implies V=\frac{\pi v^6}{4g^3}.$$

وبالنسبة إلى \((h,v,g)=(100,20,9.81)\) تكون النتيجة النهائية

$$1856532.8455.$$

مراجع إضافية

  1. صفحة المسألة: https://projecteuler.net/problem=317
  2. حركة المقذوفات: https://ar.wikipedia.org/wiki/مقذوف
  3. جسم دوراني: https://ar.wikipedia.org/wiki/جسم_دوراني