Description

1502: [NOI2005]月下柠檬树 - BZOJ-LMLPHP

Input

文件的第1行包含一个整数n和一个实数alpha,表示柠檬树的层数和月亮的光线与地面夹角(单位为弧度)。第2行包含n+1个实数h0,h1,h2,…,hn,表示树离地的高度和每层的高度。第3行包含n个实数r1,r2,…,rn,表示柠檬树每层下底面的圆的半径。上述输入文件中的数据,同一行相邻的两个数之间用一个空格分隔。输入的所有实数的小数点后可能包含1至10位有效数字。
Output

输出1个实数,表示树影的面积。四舍五入保留两位小数。
Sample Input
2 0.7853981633
10.0 10.00 10.00
4.00 5.00
Sample Output
171.97
HINT

1≤n≤500,0.3

存个simpson模板

 uses math;
const
maxn=;
eps=1e-7;
var
x,rr,fx1,fy1,fx2,fy2,k:array[..maxn]of double;
n:longint;
a,l,r,m,fl,fr,fm:double; function simpson(l,r,fl,fr,fm:double):double;
begin
exit((r-l)/*(fl+fr+*fm));
end; function f(a:double):double;
var
i:longint;
begin
f:=;
for i:= to n do
begin
if abs(a-x[i])<rr[i] then f:=max(f,sqrt(sqr(rr[i])-sqr(a-x[i])));
if (a>fx1[i]) and (a<fx2[i]) then f:=max(f,fy1[i]+(a-fx1[i])*k[i]);
end;
end; function area(l,m,r,fl,fm,fr,pre:double):double;
var
ll,rr,fll,frr,ls,rs:double;
begin
ll:=(l+m)/;rr:=(m+r)/;fll:=f(ll);frr:=f(rr);
ls:=simpson(l,m,fl,fm,fll);rs:=simpson(m,r,fm,fr,frr);
if abs(ls+rs-pre)<eps then exit(pre);
exit(area(l,ll,m,fl,fll,fm,ls)+area(m,rr,r,fm,frr,fr,rs));
end; procedure main;
var
i:longint;
begin
read(n,a);a:=/tan(a);
for i:= to n+ do read(x[i]);
for i:= to n+ do x[i]:=x[i]+x[i-];
for i:= to n+ do x[i]:=x[i]*a;
for i:= to n do read(rr[i]);
r:=x[n+];l:=x[n+];
for i:= to n do
begin
if x[i]-rr[i]<l then l:=x[i]-rr[i];
if x[i]+rr[i]>r then r:=x[i]+rr[i];
end;
for i:= to n do
if (x[i]-rr[i]<x[i+]-rr[i+]) and (x[i]+rr[i]<x[i+]+rr[i+]) then
begin
fx1[i]:=x[i]+rr[i]*(rr[i]-rr[i+])/(x[i+]-x[i]);fy1[i]:=sqrt(sqr(rr[i])-sqr(fx1[i]-x[i]));
fx2[i]:=x[i+]+rr[i+]*(rr[i]-rr[i+])/(x[i+]-x[i]);fy2[i]:=sqrt(sqr(rr[i+])-sqr(fx2[i]-x[i+]));
if abs(fx2[i]-fx1[i])>eps then k[i]:=(fy2[i]-fy1[i])/(fx2[i]-fx1[i]);
end;
m:=(l+r)/;fl:=f(l);fr:=f(r);fm:=f(m);
writeln(*area(l,m,r,fl,fm,fr,simpson(l,r,fl,fr,fm))::);
end; begin
main;
end.
05-11 09:41