给出N个点,让你画一个最小的包含所有点的圆。
给出N个点,让你画一个最小的包含所有点的圆。
先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000.0)
输出圆的半径,及圆心的坐标
裸的最小覆盖圆
因为输出必须保留10位小数(谁写的SPJ),所以一直过不了。。直到找到标程研究半天终究过了
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #include<functional> #include<cmath> #include<cctype> #include<cassert> #include<climits> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define ForD(i,n) for(int i=n;i;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define RepD(i,n) for(int i=n;i>=0;i--) #define MEM(a) memset(a,0,sizeof(a)) #define MEMI(a) memset(a,127,sizeof(a)) #define MEMi(a) memset(a,128,sizeof(a)) #define INF (2139062143) #define F (1000000009) #define MAXN (100000+10) #define MAXXi (10000.0) #define eps (1e-7) typedef long long ll; long double sqr(long double x){return x*x;} struct P { double x,y; P(){} P(double _x,double _y):x(_x),y(_y){} friend long double dis(P a,P b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));} }a[MAXN]; struct V { double x,y; V(){} V(P a,P b):x(b.x-a.x),y(b.y-a.y){} friend long double operator*(V a,V b){return a.x*b.y-a.y*b.x;} }; struct C { P o; long double r; C(){} C(P _o,long double _r):o(_o),r(_r){} C(P a,P b,P c) { long double C1=sqr(b.x)-sqr(a.x)+sqr(b.y)-sqr(a.y),C2=sqr(c.x)-sqr(b.x)+sqr(c.y)-sqr(b.y); long double A1=2*(b.x-a.x),A2=2*(c.x-b.x),B1=2*(b.y-a.y),B2=2*(c.y-b.y); o.x=(C1*B2-C2*B1)/(A1*B2-A2*B1); o.y=(C1*A2-C2*A1)/(B1*A2-B2*A1); r=dis(o,c); } C(P a,P b) { o=P((a.x+b.x)/2,(a.y+b.y)/2); r=dis(o,a); } bool in(P a){return dis(a,o)<=r;} }st; int n; int main() { //freopen("bzoj1336.in","r",stdin); scanf("%d",&n); For(i,n) scanf("%lf%lf",&a[i].x,&a[i].y); while (rand()%6000==0) { int i=rand()%n+1,j=rand()%n+1; if (i^j) swap(a[i],a[j]); } st=C(a[1],0); Fork(i,2,n) { if (!st.in(a[i])) { st=C(a[1],a[i]); Fork(j,2,i-1) { if (!st.in(a[j])) { st=C(a[j],a[i]); For(k,j-1) { if (!st.in(a[k])) st=C(a[j],a[i],a[k]); } } } } } cout.setf(ios::fixed); cout.precision(9); cout<<st.r<<endl; cout<<st.o.x<<' '<<st.o.y<<endl; //while (1); return 0; }