2016ICPC沈阳站G - Do not pour out(积分)

    科技2022-07-13  125

    G - Do not pour out

    题意:

    长度为2,直径为2的圆柱体杯子。杯子中液体的高度为d,求当杯子倾斜到最大角度且液体没有倒出来的时候,液体的表面积。

    思路

    分两种情况讨论: 1、倾斜时液体覆盖了杯底(较为简单) 液体体积: V = π ∗ r 2 ∗ d = π ∗ d V = \pi*r^2*d=\pi*d V=πr2d=πd π ∗ r 2 ∗ x 2 + π ∗ r ∗ r ∗ ( 2 − x ) = V = π ∗ d \cfrac{\pi*r^2*x}{2}+\pi*r*r*(2-x)=V=\pi*d 2πr2x+πrr(2x)=V=πd 解得: x = 4 − 2 ∗ d x = 4-2*d x=42d 所以:椭圆长半轴 a = x 2 + 4 2 a =\cfrac{\sqrt{x^2+4}}{2} a=2x2+4 液体表面积: s = π ∗ a ∗ b = π ∗ a s =\pi*a*b=\pi*a s=πab=πa 1、倾斜时液体没有覆盖了杯底 根据 y y y 对水体截面积 s s s 进行积分

    当phi从水杯底部走到杯口时,phi在不断变化中,命名一个变化的角度为 θ \theta θ θ \theta θ 表示 y y y ,根据相似三角形: 1 − c o s ( θ ) 1 − c o s ( ϕ ) = 2 − y 2 \cfrac{1-cos(\theta)}{1-cos(\phi)}=\cfrac{2-y}{2} 1cos(ϕ)1cos(θ)=22y 所以: y = 2 − 2 ( 1 − c o s ( θ ) ) 1 − c o s ( ϕ ) y=2-\cfrac{2(1-cos(\theta))}{1-cos(\phi)} y=21cos(ϕ)2(1cos(θ)) 对于水的横截面S 等于扇形面积减去三角形的面积: S = 2 ϕ 2 π π − s i n ϕ c o s ϕ = ϕ − s i n ϕ c o s ϕ S=\cfrac{2\phi}{2\pi}\pi-sin\phi cos\phi=\phi-sin\phi cos\phi S=2π2ϕπsinϕcosϕ=ϕsinϕcosϕ 那么对于变化中的横截面积为: s = θ − s i n θ c o s θ s=\theta-sin\theta cos\theta s=θsinθcosθ 对y进行积分: ∫ 0 2 s d y = ∫ 0 2 θ − s i n θ c o s θ d y \int_{0}^{2}sdy=\int_{0}^{2}\theta-sin\theta cos\theta dy 02sdy=02θsinθcosθdy 又因为: d y = d ( 2 − 2 ( 1 − c o s ( θ ) ) 1 − c o s ( ϕ ) ) = − 2 s i n θ 1 − c o s ( ϕ ) d θ dy=d(2-\cfrac{2(1-cos(\theta))}{1-cos(\phi)})=\cfrac{-2sin\theta}{1-cos(\phi)}d\theta dy=d(21cos(ϕ)2(1cos(θ)))=1cos(ϕ)2sinθdθ 上下限更新为: ϕ → 0 \phi\rarr0 ϕ0 所以原式 = ∫ ϕ 0 ( θ − s i n θ c o s θ ) × − 2 s i n θ 1 − c o s ( ϕ ) d θ =\int_{\phi}^0(\theta-sin\theta cos\theta)\times{\cfrac{-2sin\theta}{1-cos(\phi)}}d\theta =ϕ0(θsinθcosθ)×1cos(ϕ)2sinθdθ = − 2 1 − c o s ϕ ∫ ϕ 0 ( θ − s i n θ c o s θ ) s i n θ d θ =\cfrac{-2}{1-cos\phi}\int_{\phi}^0(\theta-sin\theta cos\theta)sin\theta d\theta =1cosϕ2ϕ0(θsinθcosθ)sinθdθ = − 2 1 − c o s ϕ [ ∫ ϕ 0 θ s i n θ d θ − ∫ ϕ 0 s i n 2 θ c o s θ d θ ] =\cfrac{-2}{1-cos\phi}[\int_{\phi}^0\theta sin\theta d\theta - \int_{\phi}^0sin^2\theta cos\theta d\theta] =1cosϕ2[ϕ0θsinθdθϕ0sin2θcosθdθ] = − 2 1 − c o s ϕ [ − θ c o s θ + s i n θ − 1 3 s i n 3 θ ] ϕ 0 =\cfrac{-2}{1-cos\phi}[-\theta cos\theta +sin\theta -\cfrac{1}{3}sin^3\theta ]^0_\phi =1cosϕ2[θcosθ+sinθ31sin3θ]ϕ0 = 2 1 − c o s ϕ × ( − ϕ c o s ϕ + s i n ϕ − 1 3 s i n 3 ϕ ) =\cfrac{2}{1-cos\phi} \times(-\phi cos\phi +sin\phi -\cfrac{1}{3}sin^3\phi) =1cosϕ2×(ϕcosϕ+sinϕ31sin3ϕ) 二分答案区间 [ 0 , π ] [0,\pi] [0,π] 得到 ϕ \phi ϕ 的值,然后计算长半轴:

    L = 2 2 + ( 1 − c o s ϕ ) 2 L=\sqrt{2^2+(1-cos\phi)^2} L=22+(1cosϕ)2 x 0 = L − a , y 0 = s i n ϕ x_0=L-a,y_0=sin\phi x0=La,y0=sinϕ 在 椭圆上,带入椭圆公式 x 2 a 2 + y 2 = 1 \cfrac{x^2}{a^2}+y^2=1 a2x2+y2=1求出a的值为 a = L 1 + 1 − y 0 2 , 当 ϕ < = π 2 a=\cfrac{L}{1+\sqrt{1-y_0^2}},当 \phi<=\cfrac{\pi}{2} a=1+1y02 Lϕ<=2π a = L 1 − 1 − y 0 2 , 当 ϕ > π 2 a=\cfrac{L}{1-\sqrt{1-y_0^2}},当 \phi>\cfrac{\pi}{2} a=11y02 Lϕ>2π 对椭圆中蓝色部分进行积分: s 0 = ∫ 0 L − a 1 − x 2 a 2 d x s_0=\int_0^{L-a}\sqrt{1-\cfrac{x^2}{a^2}}dx s0=0La1a2x2 dx x = a s i n t , d x = a c o s t d t x = asint,dx=acostdt x=asint,dx=acostdt 上限变为 a s i n ( L − a a ) asin(\cfrac{L-a}{a}) asin(aLa) 所以 s 0 = 1 a ∫ 0 a s i n L − a a a 1 − s i n 2 t × a c o s t d t = a [ t / 2 + s i n ( 2 t ) / 4 ] 0 a s i n L − a a s_0=\cfrac{1}{a}\int^{asin\cfrac{L-a}{a}}_0 a\sqrt{1-sin^2t}\times acost dt=a[t/2+sin(2t)/4]^{asin\cfrac{L-a}{a}}_0 s0=a10asinaLaa1sin2t ×acostdt=a[t/2+sin(2t)/4]0asinaLa 终于得到结果啦!: S = π a b / 2 + 2 s 0 = π a / 2 + 2 ∗ s 0 S = \pi ab/2+2s_0=\pi a/2+2*s0 S=πab/2+2s0=πa/2+2s0

    代码:

    #include <iostream> #include <cmath> #include <cstring> #include <cstdio> #include <algorithm> #pragma warning(disable:4996) using namespace std; const double PI = acos(-1); const double eps = 1e-12; double V; double f(double x) { return 2.0 * (-x * cos(x) + sin(x) - sin(x) * sin(x) * sin(x) / 3.0) / (1.0 - cos(x)) - V; } int main() { int T; double d; scanf("%d", &T); while (T--) { scanf("%lf", &d); if (d > 1) { double x = 4 - 2 * d; double a = sqrt(4 + x * x) / 2; printf("%.5f\n", PI*a); } else if (d == 0) printf("%.5lf\n", 0.0); else { V = PI * d; double l = 0, r = PI; while (r - l > eps) { double mid = (l + r) / 2.0; if (f(mid) <= 0) l = mid; else r = mid; } double phi = l; if (phi == 0.0) phi = eps; double a, L = sqrt(4.0 + ((1 - cos(phi)) * (1 - cos(phi)))), y0 = sin(phi); if (phi >= PI / 2.0) a = L / (1 + sqrt(1 - y0 * y0)); else a = L / (1 - sqrt(1 - y0 * y0)); double x = asin((L - a) / a); double ans = PI * a / 2.0 + a * (x + sin(2 * x) / 2.0); printf("%.5lf\n", ans); } } return 0; }
    Processed: 0.013, SQL: 8