#include<stdio.h> #include<math.h> const double eps = 1e-8; const double pi = acos(-1.0); struct Point { double x,y; }; struct circle { Point pp; double r; }cir[30]; double area[30]; int n; double cir_area_inst(Point c1,double r1,Point c2,double r2) { //两圆面积交 double a1, a2, d, ret; d = sqrt((c1.x-c2.x)*(c1.x-c2.x)+(c1.y-c2.y)*(c1.y-c2.y)); //圆心距离 if ( d > r1 + r2 - eps ) return 0; //相离 if ( d < r2 - r1 + eps ) return pi*r1*r1; //内切与包含 if ( d < r1 - r2 + eps ) return pi*r2*r2; //内切与包含 a1 = acos((r1*r1+d*d-r2*r2)/2/d/r1);//相交 //余弦定理求角 a2 = acos((r2*r2+d*d-r1*r1)/2/d/r2); ret = (a1-0.5*sin(2*a1))*r1*r1 + (a2-0.5*sin(2*a2))*r2*r2; //求楔形(扇形减三角形)面积 return ret; } bool judge(Point p,double r)//枚举每个圆心 { int i,j; for(i=0;i<n;i++) { double Are = cir_area_inst(p,r,cir[i].pp,cir[i].r); if(Are<area[i])return false; } return true; } int main() { int t,i,j; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0;i<n;i++) { scanf("%lf %lf %lf",&cir[i].pp.x,&cir[i].pp.y,&cir[i].r); area[i] = pi*cir[i].r*cir[i].r/2; } Point a; double rans = 200000; //初始化符合要求的大圆半径 for(i=0;i<n;i++) { a = cir[i].pp; double l=0,r=200000,mid; while(fabs(l-r)>eps)//二分法 { mid = (l+r)/2; if(judge(a,mid)) { r =mid; if(mid<rans)//找符合要求的最小的圆 rans =mid; } else l=mid; } } printf("%.4lf\n",rans); } return 0; }
from:http://www.cnblogs.com/XDJjy/archive/2013/04/02/2995918.html