计算若干个圆与一个矩形的面积并
simpson公式 ans = ( f[l] + f[r] + 4 * f[mid] ) * (r-l) / 6
uses math;
type arr=record x,y:double; end;
const eps=1e-8;
var a,b,n,i:longint;
sl,sr,sm:double;
T:array[..] of record x,y,z,r:double; end;
f:array[..] of arr;
g:double;
function sum(sl,sr,sm,l,r:double):double;
begin
exit((sl+sr+*sm)*(r-l)/);
end;
procedure sort(l,r:longint);
var i,j:longint; x,y:double;
temp:arr;
begin
i:=l;j:=r;x:=f[(i+j) div ].x; y:=f[(i+j) div ].y;
while i<=j do
begin
while (f[i].x<x) or (f[i].x=x) and (f[i].y<y) do inc(i);
while (x<f[j].x) or (x=f[j].x) and (y<f[j].y) do dec(j);
if i<=j then
begin
temp:=f[i]; f[i]:=f[j]; f[j]:=temp;
inc(i); dec(j);
end;
end;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
function calc(xx:double):double;
var i,j,k:longint;
cnt,yy:double;
begin
k:=;
for i:= to n do
if abs(T[i].x-xx)+eps<T[i].r then
begin
yy:=sqrt(sqr(T[i].r)-sqr(T[i].x-xx));
inc(k);
f[k].x:=T[i].y-yy;
f[k].y:=T[i].y+yy;
end;
sort(,k);
i:=; cnt:=;
//if xx=a/ then writeln(f[].x::,f[].y::);
while i<=k do
begin
j:=i;
while (j<k) and (f[j+].x<=f[i].y) do
begin
inc(j);
if f[j].y>f[i].y then f[i].y:=f[j].y;
end;
if not ((f[i].y<) or (f[i].x>b)) then
begin
if (f[i].y<=b) and (f[i].x>=) then cnt:=cnt+f[i].y-f[i].x else
if (f[i].y>b) and (f[i].x<) then cnt:=cnt+b else
if (f[i].y>b) then cnt:=cnt+b-f[i].x else
if (f[i].x<) then cnt:=cnt+f[i].y;
end;
i:=j+;
end;
exit(cnt);
end;
function simpson(l,r,mid,sl,sr,sm,w:double):double;
var sm1,sm2,m1,m2,w1,w2:double;
begin
m1:=(l+mid)/;
m2:=(r+mid)/;
sm1:=calc(m1);
sm2:=calc(m2);
w1:=sum(sl,sm,sm1,l,mid);
w2:=sum(sm,sr,sm2,mid,r);
if abs(w1+w2-w)<eps then exit(w);
exit(simpson(l,mid,m1,sl,sm,sm1,w1)+simpson(mid,r,m2,sm,sr,sm2,w2));
end;
begin
assign(input,'sun.in');reset(input);
assign(output,'sun.out');rewrite(output);
readln(a,b);
readln(g);
readln(n);
for i:= to n do
begin
readln(T[i].x,T[i].y,T[i].z,T[i].r);
T[i].x:=T[i].x+cos(g/*pi)/sin(g/*pi)*T[i].z;
end;
sl:=calc(); sr:=calc(a); sm:=calc(a/);
//writeln(sl::,' ',sr::,' ',sm::);
writeln(a*b-simpson(,a,a/,sl,sr,sm,sum(sl,sr,sm,,a))::);
close(input);
close(output);
end.