傳送門biu~
考慮貢獻。我們可以發現,對於能組成凸四邊形的四個點,它們對答案的貢獻是2;對於能組成凹四邊形的四個點,它們對答案的貢獻是1。問題就轉化成了計算凹/凸四邊形的數量。
因爲凹四邊形和凸四邊形的數量和是確定的 ,而凹四邊形還有着“有中心點”這個性質,所以我們選擇計算凹四邊形。
枚舉凹四邊形的中心點,將其它點按輻角排序。如果其餘三個點到中心點的輻角差不超過 ,那麼就說明這不是一個凹四邊形。將這部分減去就能求出凹四邊形數目了。
代碼:
#include<bits/stdc++.h>
#define N 1505
using namespace std;
const double pi=acos(-1);
int n;long long t,C[N][5]={1};
struct point{int x,y;}p[N];
double a[N<<1],ans;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
C[i][0]=1;
for(int j=1;j<=4;++j){
C[i][j]=C[i-1][j]+C[i-1][j-1];
}
}
for(int i=1;i<=n;++i) scanf("%d%d",&p[i].x,&p[i].y);
for(int cnt=0,i=1;i<=n;++i,cnt=0){
for(int j=1;j<=n;++j){
if(i==j) continue;
a[++cnt]=atan2(p[j].y-p[i].y,p[j].x-p[i].x);
if(a[cnt]<0) a[cnt]+=2*pi;
}
sort(a+1,a+cnt+1);
for(int j=1;j<=cnt;++j) a[cnt+j]=a[j]+2*pi;
long long x(0);int now(1);
for(int j=1;j<=cnt;++j){
while(now<2*cnt && a[now+1]-a[j]<pi) ++now;
if(now-j>1) x+=C[now-j][2];
}
t+=C[cnt][3]-x;
}
ans=(double)(t+(C[n][4]-t)*2)/C[n][3]+3;
printf("%.6lf\n",ans);
return 0;
}