题意:给定a,b,s要求在[-a,a]选定x,在[-b,b]选定y,使得(0, 0)和(x, y)组成的矩形面积大于s,求概率
思路:这样其实就是求xy > s的概率,那么画出图形,只要求y = s / x的原函数, y = slnx,带入两点相减就能求出面积,面积比去总面积就是概率
代码:
#include <cstdio> #include <cstring> #include <cmath> int t; double a, b, s; int main() { scanf("%d", &t); while (t--) { scanf("%lf%lf%lf", &a, &b, &s); if (s == 0) printf("100.000000%%\n"); else if (s >= a * b) printf("0.000000%%\n"); else printf("%.6lf%%\n", (a * b - s - s * (log(a) - log(s/b))) / (a * b) * 100); } return 0; }
UVA 11346 - Probability(概率),布布扣,bubuko.com
原文地址:http://blog.csdn.net/accelerator_/article/details/37912499