计算几何&组合数学,也不是很难,关键是要有数学储备
平面向量叉积:a*b=xa*yb-ya*xb;当且仅当a,b共线时取等,a在b右侧时为正,a在b左侧时为负;
剩下的就是用组合数公式一顿算,最后发现只要计算一个点不在另外三个点所成三角形的情况有多少种就能出解,而这个可以枚举点然后叉积极角排序。
这题在oj上评测很囧,int64超时,longint溢出,real/double才能ac。
贴代码:
program signaling;
type point=record x,y:double; end;
var x,y:array[1..5000] of double;
a:array[1..5000] of point;
n,i:longint;
sum,ta,tb:double;
function det(a,b:point):double;
begin det:=a.x*b.y-b.x*a.y;
end;
procedure sort(l,r:longint);
var i,j:longint; mid,tmp:point;
begin i:=l; j:=r; mid:=a[(l+r)shr 1];
repeat
while det(a[i],mid)<0do inc(i);
while det(mid,a[j])<0do dec(j);
if i<=j then begin
tmp:=a[i]; a[i]:=a[j]; a[j]:=tmp;
inc(i); dec(j);
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end;
function c(n,m:int64):double;
var i:double;
begin
if m=2 then c:=n*(n-1)/2;
if m=3 then c:=n*(n-1)*(n-2)/6;
if m=4 then c:=n*(n-1)*(n-2)*(n-3)/24;
end;
procedure process(v:longint);
var i,j:longint;
begin j:=0;
for i:=1 to n do
if i<>v then begin
inc(j);
a[j].x:=x[i]-x[v];
a[j].y:=y[i]-y[v];
end;
sort(1,n-1);
for i:=1 to n-1 do a[i+n-1]:=a[i];
i:=1; j:=2;
while i<=n-1 do begin
while det(a[i],a[j])<0 do inc(j);
if j-1-i>=2 then sum:=sum+c(j-i-1,2);
inc(i);
end;
end;
begin
assign(input,'signaling.in'); reset(input);
assign(output,'signaling.out'); rewrite(output);
readln(n);
for i:=1 to n do readln(x[i],y[i]);
sum:=0;
for i:=1 to n do process(i);
ta:=2*c(n,4)-n*c(n-1,3)+sum;
tb:=c(n,3);
write(ta/tb+3:0:6);
close(input);
close(output);
end.