这个概率。。真的是不造这么求。。
然后注意到题目对精度的要求比平时要低。。所以就可以用随机化算法。。。
然后得在三角形里面撒点求凸包了。。
然而要保证撒点的平均性不是件易事。。自己也没学过概率论。。得简化一下。。
方法就是平移和仿射变换。。假设n个点定下来。。那么经过平移和仿射变换之后,并不影响这个n个点构成的凸包的性质。。那么就可以把所有三角形变换到以坐标轴为直角边的等腰三角形。。(即三角形形状不影响答案)那么撒点工作就十分简单了。。
在方阵里均匀撒点。 。然后如果不在三角形内就对称到三角形内。。然后多次求均值。。
显然次数越多越好。。然而由于时限最多跑1e6次。。这样精度就比较飘了。。
需要更多的次数。。其实由于n比较小。。可以打表。。那么次数可以达到更多次,跑个几分钟还是可以接受。。
打表代码在注释里面。。
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━━━━━━━━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1LL<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 100005
#define nm 400000
#define N 1000005
#define M(x,y) x=max(x,y)
const double pi=acos(-1);
const ll inf=998244353;
using namespace std;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
/*
struct P{
ll x,y;
bool operator<(const P&o){return x<o.x||(x==o.x&&y<o.y);}
P operator-(const P&o){return P{x-o.x,y-o.y};}
ll operator*(const P&o){return x*o.y-y*o.x;}
}p[15],s[15];
int n,t;
ll tot;
void hull(){
sort(p+1,p+1+n);
int m=0;
inc(i,1,n){
while(m>1&&(s[m-1]-s[m-2])*(p[i]-s[m-2])<0)m--;
s[m++]=p[i];
}
int k=m;
dec(i,n-1,1){
while(m>1&&(s[m-1]-s[m-2])*(p[i]-s[m-2])<0)m--;
s[m++]=p[i];
}
tot+=--m;
}
int main(){
srand(time(0));
n=9;t=100000000;
inc(i,1,t){
inc(i,1,n){
p[i].x=(ll)rand()*rand()%inf,p[i].y=(ll)rand()*rand()%inf;
if(p[i].x+p[i].y>inf)p[i].x=inf-p[i].x,p[i].y=inf-p[i].y;
}
hull();
}
return 0*printf("%lf\n",1.0*tot/t);
}
*/
const double a[]={0,0,0,3,3.666634,4.166654,4.566598,4.900027,5.185805,5.435739,5.657959};
int main(){inc(i,1,6)read();return 0*printf("%lf\n",a[read()]);}
Expected Size of Random Convex Hull
链接:https://www.nowcoder.com/acm/contest/141/I
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld
题目描述
Currently, Eddy is reading this paper "On the Expected Complexity of Random Convex Hulls"(1997). It states that the expected number of vertices of the convex hull of N points, chosen uniformly and independently from a disk is , and
for the case a convex polygon with K sides, and so on. Eddy thinks it's very interesting and now wants to research something about it. But, it seems too hard to start with something like disk or polygon.
Thus, as his first step in the research, Eddy first chooses a triangle. Now, Eddy wants to find out the expected number of points on the convex hull when uniformly randomly picking N points within the triangle. However, Eddy can't find any way to solve this problem. As his best friend, you come to help Eddy finish his research debut.
输入描述:
For first three lines, each contains two space-separated integer xi, yi indicating the points(xi, yi) of the triangle Eddy chooses.
Forth line contains one integer N indicating that N points will be randomly uniformly chosen within the given triangle.
-109 ≤ xi, yi ≤ 109
3 ≤ N ≤ 10
It's guaranteed that given input forms a non-degenerate triangle
输出描述:
Output a floating number indicating the expected number of points on the convex hull.
Absolutely or relatively error within 10-4 will be considered correct.
示例1
输入
复制
0 0
1 0
2 1
3
输出
复制
3.000000000000