bzoj1043

时间:2023-03-08 23:45:17
bzoj1043

每次做计算几何题都要做好久

考虑每个圆对答案的贡献,也就是每个圆被后面圆覆盖还有多少

可以把覆盖当成盖住一段弧度,看最后有多少没被覆盖

这就相当于线段覆盖问题了,

推推公式,算极角然后排序即可

md,pascal算极角就是麻烦

 uses math;
const pi=3.1415926535897932384626433832795;
eps=1e-4;
type node=record
l,r:double;
end; var q:array[..] of node;
x,y,r:array[..] of double;
t,j,i,n:longint;
ans:double; function dis(i,j:longint):double;
begin
exit(sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j])));
end; function have(i,j:longint):boolean;
begin
exit(r[j]-r[i]>=dis(i,j));
end; procedure swap(var a,b:node);
var c:node;
begin
c:=a;
a:=b;
b:=c;
end; function get(x,y:double):double;
begin
if x= then
begin
if y> then exit(pi/)
else exit(-pi/);
end;
get:=arctan(y/x);
if (x<) then get:=get+pi;
end; procedure sort(l,r:longint);
var i,j:longint;
x:double;
begin
i:=l;
j:=r;
x:=q[(l+r) shr ].l;
repeat
while q[i].l<x do inc(i);
while x<q[j].l do dec(j);
if not(i>j) then
begin
swap(q[i],q[j]);
inc(i);
dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; function cal(j:longint):double;
var i:longint;
d,now,l,z,an:double;
begin
for i:=j+ to n do
if have(j,i) then exit();
t:=;
for i:=j+ to n do
begin
d:=dis(i,j);
if not have(i,j) and (r[j]+r[i]>d) then
begin
inc(t);
an:=get(x[i]-x[j],y[i]-y[j]);
l:=(sqr(r[j])-sqr(r[i])+sqr(d))/(*d);
z:=arccos(l/r[j]);
q[t].l:=an-z;
q[t].r:=an+z;
// writeln(an,' ',z,' ',i,' ',x[i]-x[j],' ',y[i]-y[j]);
// readln;
end;
end;
for i:= to t do
begin
if q[i].l>*pi then q[i].l:=q[i].l-*pi;
if q[i].r>*pi then q[i].r:=q[i].r-*pi;
if q[i].l< then q[i].l:=q[i].l+*pi;
if q[i].r< then q[i].r:=q[i].r+*pi;
if q[i].l>q[i].r then
begin
inc(t);
q[t].l:=;
q[t].r:=q[i].r;
q[i].r:=*pi;
end;
end;
sort(,t);
cal:=;
now:=;
for i:= to t do
if q[i].l>now then
begin
cal:=cal+(q[i].l-now);
now:=q[i].r;
end
else if now<q[i].r then now:=q[i].r; cal:=cal+*pi-now;
if cal< then cal:=;
cal:=cal*r[j];
end; begin
readln(n);
for i:= to n do
readln(r[i],x[i],y[i]); for i:= to n do
ans:=ans+cal(i); writeln(ans::);
end.