UVA11346 - Probability(连续概率)

题目链接 https://cn.vjudge.net/problem/UVA-11346

【题意】
x[a,a]y[b,b] 区域内随机取一个点P,求以(0,0)和P为对角线的长方形面积大于S的概率(a,b>0,S>=0)

【思路】
根据对称性,只考虑第一象限 x[0,a]y[0,b] 即可,所求概率就是该区域中曲线 y=Sx 上方的面积除以总面积,定积分即可,注意当 ab<S 时答案为0,当 S 趋近于0时答案为 1

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

const double eps=1e-6;

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        double a,b,s;
        scanf("%lf%lf%lf",&a,&b,&s);
        if(a*b<=s) {puts("0.000000%");continue;}
        if(fabs(s)<eps){puts("100.000000%");continue;}
        double ans=(a*b-s+s*log(s/(a*b)))/(a*b);
        printf("%.6lf%%\n",ans*100.0);
    }
    return 0;
}
posted @ 2018-08-24 12:19  不想吃WA的咸鱼  阅读(183)  评论(0编辑  收藏  举报