思路:
随机增量法
(好吧这数据范围并不用)
//By SiriusRen #include <cmath> #include <cstdio> #include <algorithm> using namespace std; typedef double db; int n; struct P{db x,y,r;P(){}P(db X,db Y){x=X,y=Y;}}p[505],ans; P operator-(P a,P b){return P(a.x-b.x,a.y-b.y);} db dis(P a){return sqrt(a.x*a.x+a.y*a.y);} bool ck(P a){return dis(a-ans)<=ans.r;} P get(db x1,db y1,db x2,db y2,db x3,db y3){ db a1=2*(x2-x1),b1=2*(y2-y1),c1=x2*x2+y2*y2-x1*x1-y1*y1; db a2=2*(x3-x2),b2=2*(y3-y2),c2=x3*x3+y3*y3-x2*x2-y2*y2; return P((c1*b2-c2*b1)/(a1*b2-a2*b1),(a1*c2-a2*c1)/(a1*b2-a2*b1)); } int main(){ while(scanf("%d",&n)&&n){ for(int i=1;i<=n;i++)scanf("%lf%lf",&p[i].x,&p[i].y); random_shuffle(p+1,p+1+n),ans.x=ans.y=ans.r=0; for(int i=1;i<=n;i++)if(!ck(p[i])){ ans.x=ans.y=ans.r=0; for(int j=1;j<i;j++)if(!ck(p[j])){ ans=P((p[i].x+p[j].x)/2,(p[i].y+p[j].y)/2); ans.r=dis(ans-p[j]); for(int k=1;k<j;k++)if(!ck(p[k])){ ans=get(p[i].x,p[i].y,p[j].x,p[j].y,p[k].x,p[k].y); ans.r=dis(ans-p[j]); } } } printf("%.2lf %.2lf %.2lf\n",ans.x,ans.y,ans.r); } }