题解
2024-05-18 15:54:29
发布于:广东
72阅读
0回复
0点赞
#include<cmath>
#include<queue>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef double dl;
const int N=510;
const dl eps=1e-8;
struct cir{
dl x,r;
}p[N];
struct line{
dl k,b,l,r;
}q[N];
int n;
dl alpha;
inline dl py(dl a,dl b){return sqrt(a*a-b*b);}
inline dl f(dl x){
dl ans=0;
for(int i=1;i<=n;i++){
if(p[i].x-p[i].r<x&&x<p[i].x+p[i].r){
ans=max(ans,py(p[i].r,x-p[i].x));
}
}
for(int i=1;i<n;i++){
if(q[i].l<=x&&x<=q[i].r){
ans=max(ans,q[i].k*x+q[i].b);
}
}
return ans;
}
inline dl simpson(dl l,dl r){
dl mid=(l+r)/2;
return (f(l)+4*f(mid)+f(r))*(r-l)/6;
}
inline dl asr(dl l,dl r,dl ans){
dl mid=(l+r)/2;
dl l1=simpson(l,mid),r1=simpson(mid,r);
if(fabs(l1+r1-ans)<eps)return l1+r1;
return asr(l,mid,l1)+asr(mid,r,r1);
}
inline int shadow(dl a){
dl c=a*alpha;
dl d=sqrt(a*a+c*c);
return c*a/d;
}
inline void getl(int x,int y){
if(fabs(p[x].r-p[y].r)<eps){
q[x].l=p[x].x,q[x].r=p[y].x;
q[x].k=0;q[x].b=p[x].r;
return;
}
dl CA=p[y].x-p[x].x,AJ=fabs(p[x].r-p[y].r);
dl CG=p[x].r,AB=p[y].r;
dl CK=CG*AJ/CA,AI=AB*AJ/CA;
if(p[x].r>p[y].r){
q[x].l=p[x].x+CK;q[x].r=p[y].x+AI;
dl x1=q[x].l,y1=py(CG,CK);
dl x2=q[x].r,y2=py(AB,AI);
q[x].k=(y1-y2)/(x1-x2);
q[x].b=y1-q[x].k*x1;
}else{
q[x].l=p[x].x-CK;q[x].r=p[y].x-AI;
dl x1=q[x].l,y1=py(CG,CK);
dl x2=q[x].r,y2=py(AB,AI);
q[x].k=(y1-y2)/(x1-x2);
q[x].b=y1-q[x].k*x1;
}
}
int main(){
scanf("%d%lf",&n,&alpha);
alpha=1.0/tan(alpha);
for(int i=1;i<=n+1;i++){
scanf("%lf",&p[i].x);
p[i].x*=alpha;
p[i].x+=p[i-1].x;
}
for(int i=1;i<=n;i++)scanf("%lf",&p[i].r);
p[++n].r=0;
for(int i=1;i<n;i++){
getl(i,i+1);
}
dl l=p[1].x-p[1].r,r=p[n].x;
for(int i=1;i<=n;i++){
r=max(r,(p[i].x+p[i].r));
l=min(l,(p[i].x-p[i].r));
}
printf("%.2lf\n",2*asr(l,r,simpson(l,r)));
return 0;
}
这里空空如也
有帮助,赞一个