1043: [HAOI2008]下落的圆盘 - BZOJ

时间:2023-03-09 19:44:23
1043: [HAOI2008]下落的圆盘 - BZOJ

Description
1043: [HAOI2008]下落的圆盘 - BZOJ
有n个圆盘从天而降,后面落下的可以盖住前面的。求最后形成的封闭区域的周长。看下面这副图, 所有的红色线条的总长度即为所求.
Input

n ri xi y1 ... rn xn yn
Output

最后的周长,保留三位小数
Sample Input
2
1 0 0
1 1 0
Sample Output
10.472

数据规模
n<=1000

调了一晚上外加下午(弱菜写计算几何,tan函数都抄错了)

对每一个圆计算覆盖区间,然后排序,再区间合并,注意范围,我是全部弄到0到2π里

再膜拜一下z55250825,最后还是他看出错误来的

 uses math;
const
maxn=;
eps=1e-7;
var
r,x,y,ll,rr:array[..maxn*]of double;
n,tot:longint;
ans:double; procedure init;
var
i:longint;
begin
read(n);
for i:= to n do
read(r[i],x[i],y[i]);
end; function angle(a,b,c:double):double;
begin
exit(arccos((a*a+b*b-c*c)/(*a*b)));
end; function tan(x,y:double):double;
var
a:double;
begin
if abs(x)<eps then
begin
if y>-eps then exit(pi/)
else exit(pi*/);
end;
if abs(y)<eps then
begin
if x>-eps then exit()
else exit(pi);
end;
a:=arctan(y/x);
if a<-eps then a:=-a;
if x>-eps then
if y>-eps then exit(a)
else exit(*pi-a)
else
if y>-eps then exit(pi-a)
else exit(pi+a);
end; procedure swap(var x,y:double);
var
t:double;
begin
t:=x;x:=y;y:=t;
end; procedure sort(l,r:longint);
var
i,j:longint;
y:double;
begin
i:=l;
j:=r;
y:=ll[(l+r)>>];
repeat
while ll[i]+eps<y do
inc(i);
while ll[j]>y+eps do
dec(j);
if i<=j then
begin
swap(ll[i],ll[j]);
swap(rr[i],rr[j]);
inc(i);
dec(j);
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end; procedure work;
var
i,j:longint;
d,a,b,sum,xx,yy:double;
cover:boolean;
begin
for i:= to n do
begin
tot:=;
cover:=false;
for j:=i+ to n do
begin
d:=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
if (r[i]+r[j]-d<eps)or(d+r[j]-r[i]<eps) then continue;
if d+r[i]-r[j]<eps then
begin
cover:=true;
break;
end;
a:=tan(x[j]-x[i],y[j]-y[i]);
b:=angle(d,r[i],r[j]);
inc(tot);
ll[tot]:=a-b;
rr[tot]:=a+b;
if ll[tot]<-eps then
begin
ll[tot+]:=*pi+ll[tot];
rr[tot+]:=*pi;
ll[tot]:=;
inc(tot);
end;
if rr[tot]>*pi+eps then
begin
rr[tot+]:=rr[tot]-*pi;
ll[tot+]:=;
rr[tot]:=*pi;
inc(tot);
end;
end;
if cover then continue;
sort(,tot);
inc(tot);
ll[tot]:=;
rr[tot]:=;
sum:=;
xx:=;
yy:=;
for j:= to tot do
if ll[j]+eps<=yy then
begin
if rr[j]+eps<=yy then continue;
yy:=rr[j];
end
else
begin
sum:=sum+yy-xx;
xx:=ll[j];
yy:=rr[j];
end;
ans:=ans+(*pi-sum)*r[i];
end;
write(ans::);
end; begin
init;
work;
end.