UVA11346 题解

· · 题解

容易得知 [-a,a]\times[-b,b] 的矩形被坐标轴分为了四个相等的小矩形,因为是求概率,那我们只需对一个象限中的情况求解。

先特判,如果 ab<S,概率为 0\%;如果 S=0,概率为 100\%

P(x,y),那么以 OP 为对角线的矩形面积 S_P=xy,因为要使 S_P>S,则有 xy>S,即 y>\dfrac{S}{x},那我们就要求 ab 与函数 y=\dfrac{S}{x} 围成的部分的面积(可以参考我画的图理解,就是求图中曲线与矩形相交区域的面积,记这一块面积为 S_0)。既然是要求与曲线有关的面积,那就要把微积分给搬出来了,接下来内容可以参照图象理解。

\begin{aligned} S_0&=ab-\displaystyle\int_{\frac{S}{b}}^{a}\dfrac{S}{x}\mathrm{d}x-\dfrac{S}{b}\times b \\&=ab-S\displaystyle\int_{\frac{S}{b}}^{a}\dfrac{1}{x}\mathrm{d}x-S\\&=ab-S-S\times\ln |x| \large{{|}^a_{\frac{S}{b}}}\\&=ab-S-S\times(\ln a - \ln \dfrac{S}{b})\\&=ab-S-S\times \ln\dfrac{ab}{S}\end{aligned}

因为是要求概率,那么:

\begin{aligned}P(S_0>S)&=\dfrac{S_0}{S}\\&=\dfrac{ab-S-S\times \ln\dfrac{ab}{S}}{ab}\end{aligned}

代入计算即可,记得要以百分数的形式输出。

#include<bits/stdc++.h>

using namespace std;

int n;
double a, b, s;

int main() {
    cin >> n;
    while (n--) {
        cin >> a >> b >> s;
        if (s > a * b) cout << "0.000000%\n";
        else if (s == 0) cout << "100.000000%\n";
        else printf("%lf%\n", 100 * (a * b - s - s * log(a * b / s)) / a / b);
    }
}