求两个圆的重合面积+二分 hdu3264

  1 #include <iostream>
  2 #include <cstdio>
  3 #include <cstring>
  4 #include <algorithm>
  5 #include <cmath>
  6 
  7 using namespace std;
  8 
  9 struct circle
 10 {
 11     double x,y,r;
 12 }c[25];
 13 
 14 double exp1 = 10e-9;
 15 double reans[25];
 16 
 17 double iabs(double a)
 18 {
 19     if(a<0)
 20         return -a;
 21     else
 22         return a;
 23 }
 24 
 25 double mianji(circle c1)
 26 {
 27     return c1.r*c1.r*acos(-1);
 28 }
 29 
 30 double jieguo(circle c1,circle c2,double r)
 31 {
 32     double b = sqrt((c1.x-c2.x)*(c1.x-c2.x)+(c1.y-c2.y)*(c1.y-c2.y));
 33     double c = c2.r;
 34     double a = r;
 35     if(a+c<=b)
 36         return 0;
 37     if(b<=iabs(a-c))
 38     {
 39         return min(a,c)*min(a,c)*acos(-1);
 40     }
 41     double cos1 = (b*b+c*c-a*a)/2/c/b;
 42     double s1 = c*c*acos(cos1);
 43     double cos2 = (a*a+b*b-c*c)/2/a/b;
 44     double s2 = a*a*acos(cos2);
 45     double s3 = a*b*sin(acos(cos2));
 46     double s4=s1+s2-s3;
 47     return s4;
 48 }
 49 
 50 int main()
 51 {
 52     int T;
 53     scanf("%d",&T);
 54     while(T--)
 55     {
 56         int n;
 57         scanf("%d",&n);
 58         for(int i=0;i<n;i++)
 59         {
 60             scanf("%lf%lf%lf",&c[i].x,&c[i].y,&c[i].r);
 61         }
 62         memset(reans,0,sizeof(reans));
 63         for(int i=0;i<n;i++)
 64         {
 65             for(int t=0;t<n;t++)
 66             {
 67                 double s=c[t].r*c[t].r*acos(-1)/2;
 68                 double mar=sqrt((c[i].x-c[t].x)*(c[i].x-c[t].x)+(c[i].y-c[t].y)*(c[i].y-c[t].y))+c[t].r;
 69                 double mir=sqrt((c[i].x-c[t].x)*(c[i].x-c[t].x)+(c[i].y-c[t].y)*(c[i].y-c[t].y));
 70                 double ans=0;
 71                 double r=mir;
 72                 while(iabs(ans-s)>exp1)
 73                 {
 74                     if(ans<s)
 75                     {
 76                         mir=r;
 77                         r=(mir+mar)/2;
 78                         ans=jieguo(c[i],c[t],r);
 79                     }
 80                     else
 81                     {
 82                         mar=r;
 83                         r=(mir+mar)/2;
 84                         ans=jieguo(c[i],c[t],r);
 85                     }
 86                 }
 87                 if(reans[i]<r)
 88                     reans[i]=r;
 89             }
 90         }
 91         double ss=reans[0];
 92         for(int i=1;i<n;i++)
 93         {
 94             if(reans[i]<ss)
 95                 ss=reans[i];
 96         }
 97         printf("%.4lf\n",ss);
 98     }
 99     return 0;
100 }
View Code

 

posted @ 2015-10-03 10:24  相儒以沫  阅读(397)  评论(0编辑  收藏  举报