这个。。初看这个题型竟然看成最小包围圈= =!
然后算法感觉比较奇怪。。叫什么随机增量法。。不过个人感觉是暴力枚举吧。。
由于3点确定一圆,所以枚举3个点,如果有点在圆外那么加入该点之后该点必定在覆盖圆上。。
然后据说这方法的时间复杂度的期望是O(n)。。。给窝感觉却不止o(n)。。证明看不懂。。
实际上貌似真的没那么快。。。500都跑60ms是闹哪样?
然后求圆心的方法也比较奇怪。。估计是推完公式后直接整理出来的。。就直接当结论用了,懒得证。。
所以总体来讲就是一个板子。。背!
/** * ┏┓ ┏┓ * ┏┛┗━━━━━━━┛┗━━━┓ * ┃ ┃ * ┃ ━ ┃ * ┃ > < ┃ * ┃ ┃ * ┃... ⌒ ... ┃ * ┃ ┃ * ┗━┓ ┏━┛ * ┃ ┃ Code is far away from bug with the animal protecting * ┃ ┃ 神兽保佑,代码无bug * ┃ ┃ * ┃ ┃ * ┃ ┃ * ┃ ┃ * ┃ ┗━━━┓ * ┃ ┣┓ * ┃ ┏┛ * ┗┓┓┏━┳┓┏┛ * ┃┫┫ ┃┫┫ * ┗┻┛ ┗┻┛ */ #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include<cmath> #include<map> #include<stack> #define inc(i,l,r) for(int i=l;i<=r;i++) #define dec(i,l,r) for(int i=l;i>=r;i--) #define link(x) for(edge *j=h[x];j;j=j->next) #define mem(a) memset(a,0,sizeof(a)) #define ll long long #define eps 1e-8 #define succ(x) (1<<x) #define lowbit(x) (x&(-x)) #define sqr(x) ((x)*(x)) #define mid (x+y>>1) #define NM 400005 #define nm 1000498 #define pi 3.1415926535897931 using namespace std; const ll inf=1e9; ll read(){ ll x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); return f*x; } struct P{ double x,y; P(double x=0,double y=0):x(x),y(y){} P operator+(const P&o){return P(x+o.x,y+o.y);} P operator-(const P&o){return P(x-o.x,y-o.y);} double operator*(const P&o){return x*o.y-y*o.x;} P operator/(const double&t){return P(x/t,y/t);} }p[NM],c; double dis(P o){return sqrt(sqr(o.x)+sqr(o.y));} int n; double r; P cir(P a,P b,P c){ P p1=b-a,p2=c-a; double t=p1*p2,t1=(sqr(p1.x)+sqr(p1.y))/2,t2=(sqr(p2.x)+sqr(p2.y))/2; if(fabs(t)<eps){ t=dis(b-c);t1=dis(p1);t2=dis(p2); if(t1>t2&&t1>t)return (a+b)/2; if(t2>t)return (a+c)/2; return (b+c)/2; } return a+P(t1*p2.y-t2*p1.y,t2*p1.x-t1*p2.x)/t; } void mcc(){ random_shuffle(p,p+n); c=p[1];r=0; inc(i,2,n)if(dis(p[i]-c)>r+eps){ c=p[i];r=0; inc(j,1,i-1)if(dis(p[j]-c)>r+eps){ c=(p[i]+p[j])/2;r=dis(p[i]-c); inc(k,1,j-1)if(dis(p[k]-c)>r+eps){ c=cir(p[i],p[j],p[k]); r=dis(p[i]-c); } } } } int main(){ //freopen("data.in","r",stdin); while(n=read()){ inc(i,1,n)scanf("%lf%lf",&p[i].x,&p[i].y); mcc(); printf("%.2lf %.2lf %.2lf\n",c.x,c.y,r); } return 0; }
