bzoj 1043 [HAOI2008]下落的圆盘——圆的周长

题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1043

算每个圆被它后面的圆盖住了多少圆弧即可。注意判断这个圆完全被后面盖住的情况。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define db double
using namespace std;
const int N=1005; const db pi=acos(-1),pi2=pi*2;
int n;db x[N],y[N],r[N],rf[N],ans;
struct Node{
  db l,r;
  Node(db a=0,db b=0):l(a),r(b) {}
  bool operator< (const Node &b)const
  {return l<b.l;}
}a[N<<1];
db Sqr(db x){return x*x;}
db dMx(db a,db b){return a>b?a:b;}
db Fix(db a){while(a>pi2)a-=pi2;while(a<0)a+=pi2;return a;}
int main()
{
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
    scanf("%lf%lf%lf",&r[i],&x[i],&y[i]),rf[i]=r[i]*r[i];
  for(int i=1;i<=n;i++)
    {
      int cnt=0;bool flag=0;
      for(int j=i+1;j<=n;j++)
    {
      db d=Sqr(x[i]-x[j])+Sqr(y[i]-y[j]),sd=sqrt(d);
      if(sd>=r[i]+r[j]||r[j]+sd<=r[i])continue;
      if(r[i]+sd<=r[j]){flag=1;break;}
      db fx=atan2(y[j]-y[i],x[j]-x[i]);
      db k=acos((rf[i]+d-rf[j])/(2*r[i]*sd));
      db l=Fix(fx-k),r=Fix(fx+k);//Fix
      if(l<r)a[++cnt]=Node(l,r);
      else a[++cnt]=Node(0,r),a[++cnt]=Node(l,pi2);
    }
      if(flag)continue;///
      sort(a+1,a+cnt+1);
      db ret=pi2;
      for(int x=1,y;x<=cnt;x=y)
    {
      db R=a[x].r;
      for(y=x+1;y<=cnt&&a[y].l<=R;y++)R=dMx(R,a[y].r);
      ret-=R-a[x].l;
    }
      ans+=r[i]*ret;
    }
  printf("%.3f\n",ans);
  return 0;
}

 

posted on 2018-12-19 16:13  Narh  阅读(152)  评论(0编辑  收藏  举报

导航