题意简单:
参考博客:https://blog.csdn.net/weixin_43350051/article/details/97139683 随机数方法参考了
参考博客2:https://blog.csdn.net/ftx456789/article/details/96478804 这篇很好,正好复习了我的概率论 我觉得比赛时候有必要带概率论的书了。
#include <bits/stdc++.h>
#define LL long long
const int maxn = 1e7 + 10;
using namespace std;
struct point{
double x,y;
point(){}
point(double _x,double _y):x(_x),y(_y){}
double operator^(const point & tmp )const{
return x*tmp.y-y*tmp.x;
}
point operator-(const point & tmp)const{
point res;
res.x=x-tmp.x;
res.y=y-tmp.y;
return res;
}
};
double S(point a,point b,point c)//这里用向量算的面积还没除以2
{
return fabs((b-a)^(c-a));
}
bool judge(point p,point a,point b,point c)
{
if(S(p,a,b)+S(p,a,c)+S(p,b,c)==S(a,b,c))
{
return true;
}
return false;
}
int main()
{
point a=point(0,0);
point b=point(5000,5000);
point c=point(5000,0);
int cnt=0;
double sum=0;
srand(time(0));
double x,y;
for(int i=0;i<1000000;i++)
{
x=rand();
y=rand();
point p(x,y);
if(judge(p,a,b,c)==true)
{
sum+=max(S(p,a,b),max(S(p,a,c),S(p,b,c)));
cnt++;
}
}
cout<<((sum/cnt)*36/S(a,b,c))/2;
return 0;
}
之后校赛,我出一道题目,我就以这道题为模板除了一道
题目如下:
这个结论也不难证明,用概率论积分多次即可。具体过程之后再说。