UVA 11346 Probability (几何概型, 积分)

题目链接:https://uva.onlinejudge.org/index.php?

option=com_onlinejudge&Itemid=8&page=show_problem&problem=2321


题目大意:在A是一个点集 A = {(x, y) | x ∈[-a, a],y∈[-b, b]},求取出的点和(0, 0)构成的矩形面积大于S的概率


题目分析:由对称性,考虑第一象限就可以,最好还是先设xy = S。得到反比例函数y = S / x,先求小于S的概率,就是反比例函数与边界以及x轴y轴围成的面积,这部分面积分为两块,一块是高为b,宽为min(s / b, a)的矩形,还有一块须要积分,只是y = S / x这个积分也太简单Y = S*ln(x)。区间就是min(s / b, a)到a,然后用a * b减去那两块面积和就是第一象限中选点大于S的概率。一開始要特判一下100%的情况,不然会变成无穷大

#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
double const EPS = 1e-10;

int main()
{
    int T;
    scanf("%d", &T);
    while(T --)
    {
        double a, b, s;
        scanf("%lf %lf %lf", &a, &b, &s);
        if(s - 0 < EPS)
        {
            printf("100.000000%%
");
            continue;
        }
        double x1 = min(s / b, a);
        double s1 = b * x1 + s * log(a / x1);
        double s2 = a * b - s1;
        double sum = a * b;
        double part = s2;
        double ans = part / sum * 100.0;
        printf("%.6f%%
", fabs(ans));
    }
}


原文地址:https://www.cnblogs.com/liguangsunls/p/7093686.html