zj说"那明天来一道概率论吧"(过了好几天.....
真的是概率论....
在0<x<5 0<y<10区域面积内 (x,y)和(0,0)围城的面积大于20 的概率
见图... 用积分..代码有借鉴
#include<iostream>
#include<string>
#include<algorithm>
#include"math.h"
//#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--)
{
double x, y, s;
cin >> x >> y >> s;
// double x1 = min(x, s / y);
if (s >= x*y)
{
cout << "0.000000%" << endl;
continue;
}
else if (s == 0)
{
cout << "100.000000%" << endl;
continue;
}
else{
double x1 = s / y;
double S = 0;
//if (s > 1e-9)//... if s==0
S = x1*y + s*(log(x) - log(x1));
double ans = (1 - S / (x*y)) * 100;
printf("%7f%%\n", ans);//here are two%
}
}
return 0;
}
double x1 = min(x, s / y);
//if (s > 1e-9)//... if s==0
这两行优化是相辅相成的..... 对应的特殊情况一个是s==0 ,百分之百啊.. 但是s=0对下面就会造成影响
还有就是给的面积太大的时候 不设置条件就会算出154%这种
要么用上面那2行 要么用我简化过了的..... 简化过了的看着简单啊但是似乎多套了个if
这时候就不如上面那两行省事了.....
还幸好这是算数的数学题才比较有用(拔毛)
还是斩草除根(上面那2行)比较一了百了
%%就是%啊
**这种面积啊什么的多考虑两个极端/越界/特殊点,两头都代进去试试