[bzoj1913]信号覆盖
考虑一个四边形,凸会多贡献2,凹会多贡献1.
所以我们要求出凸/凹四边形的个数。
考虑四边形任意选两个点,另外两个点在这两个点的连线两侧的情况。对于凸四边形我们可以找两个,凹四边形我们可以找三个。然后就可以极角排序扫一遍了。
- 代码
#include<bits/stdc++.h>
using namespace std;
typedef double db;
const db eps = 1e-7,PI = acos(-1);
struct Node{
db x,y,ang;
Node(db x=0, db y=0):x(x),y(y),ang(atan2(y,x)){}
Node operator - (const Node b)const{return Node(x-b.x,y-b.y);}
Node operator + (const Node b)const{return Node(x+b.x,y+b.y);}
db operator * (const Node b)const{return x*b.y-y*b.x;}
Node operator ^ (const db b)const{return Node(x*b,y*b);}
db angle()const {return atan2(y,x);}
void read(){scanf("%lf%lf",&x,&y);}
bool operator < (const Node b)const{
return ang<b.ang+eps;
}
Node rev(){return Node(-x,-y);}
};
const int N = 6010;
int n; Node nd[N];
Node t[N];
typedef long long ll;
ll ans = 0;
bool on_right(Node a,Node b){//strictly right
return a*b < 0;
}
inline void solve(int sz){
sort(t+1,t+sz+1);
for(int i=1;i<=sz;i++){
t[i].ang = t[i].angle();
t[i+sz]=t[i]; t[i+sz].ang = t[i].ang+2*PI;
}
int j = 1;
for(int i=1;i<=sz;i++){
Node nxt = t[i].rev();nxt.ang = t[i].ang + PI;
if(j<=i)j=i;
while(j+1<=i+sz && on_right(nxt,t[j+1]) ) ++j;
ll t = j-i;
ans+=1ll*(sz-1-t)*t;
}
}
int main()
{
cin >> n ;
for(int i=1;i<=n;i++)nd[i].read();
for(int i=1;i<=n;i++){
int cnt=0;
for(int j=1;j<=n;j++)if(j!=i)t[++cnt] = nd[j]-nd[i];
solve(cnt);
}
ans/=2;
ll tot = 1ll*n*(n-1)*(n-2)/6;
//ans += 1ll*3*n*(n-1)*(n-2)/6;
ll tot2 = 1ll*n*(n-1)*(n-2)*(n-3)/24;
ll inner = ans - 2 * tot2;
ll outer = tot2 - inner;
ans = tot*3 + inner + outer*2;
printf("%.6lf",(db)ans/tot);
}