# 最小圆覆盖学习笔记

## 最小圆覆盖

（你要问为什么？一会儿会解决吧）

 cq(i,2,n){
if(dis(a[i],o)>ri+eps){
o=a[i];ri=0;
cq(j,1,i-1){
if(dis(o,a[j])>ri+eps){
o.x=(a[i].x+a[j].x)/2;
o.y=(a[i].y+a[j].y)/2;
ri=dis(o,a[j]);
cq(k,1,j-1){
if(dis(o,a[k])>ri+eps){
tt(a[i],a[j],a[k]);
}
}
}
}
}
}


## 三点定圆

$\begin{cases} (x_1−x_0)^2+(y_1−y_0)^2=r^2\\ (x_2−x_0)^2+(y_2−y_0)^2=r^2\\ (x_3−x_0)^2+(y_3−y_0)^2=r^2\\ \end{cases}$

$(x_1−x_2)x_0+(y_1−y_2)y_0=\frac{(x^2_1−x^2_2)−(y^2_2−y^2_1)}{2}$
$(x_1−x_3)x_0+(y_1−y_3)y_0=\frac{(x^2_1−x^2_3)−(y^2_3−y^2_1)}{2}$

$a=x_1−x_2$
$b=y_1−y_2$
$c=x_1−x_3$
$d=y_1−y_3$
$e=\frac{(x^2_1−x^2_2)−(y^2_2−y^2_1)}{2}$
$f=\frac{(x^2_1−x^2_3)−(y^2_3−y^2_1)}{2}$

de−bf

$x_0=\frac{de−bf}{bc-ad}$
$y_0=\frac{af−ce}{bc-ad}$

void tt(Point p1,Point p2,Point p3){
double a,b,c,d,e,f;
a=p2.y-p1.y;
b=p3.y-p1.y;
c=p2.x-p1.x;
d=p3.x-p1.x;
f=p3.x*p3.x+p3.y*p3.y-p1.x*p1.x-p1.y*p1.y;
e=p2.x*p2.x+p2.y*p2.y-p1.x*p1.x-p1.y*p1.y;
o.x=(a*f-b*e)/(2*a*d-2*b*c);
o.y=(d*e-c*f)/(2*a*d-2*b*c);
ri=dis(o,p1);
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define cq(i,s,n) for(int i=s;i<=n;i++)
using namespace std;
const double eps=1e-12;
struct Point{
double x,y;
}a[500005];
Point o;
int n;
double ri;
double dis(Point a,Point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

void tt(Point p1,Point p2,Point p3){
double a,b,c,d,e,f;
a=p2.y-p1.y;
b=p3.y-p1.y;
c=p2.x-p1.x;
d=p3.x-p1.x;
f=p3.x*p3.x+p3.y*p3.y-p1.x*p1.x-p1.y*p1.y;
e=p2.x*p2.x+p2.y*p2.y-p1.x*p1.x-p1.y*p1.y;
o.x=(a*f-b*e)/(2*a*d-2*b*c);
o.y=(d*e-c*f)/(2*a*d-2*b*c);
ri=dis(o,p1);
}

int main(){
scanf("%d",&n);
cq(i,1,n){
scanf("%lf%lf",&a[i].x,&a[i].y);
}
random_shuffle(a+1,a+n+1);
o=a[1];ri=0;
cq(i,2,n){
if(dis(a[i],o)>ri+eps){
o=a[i];ri=0;
cq(j,1,i-1){
if(dis(o,a[j])>ri+eps){
o.x=(a[i].x+a[j].x)/2;
o.y=(a[i].y+a[j].y)/2;
ri=dis(o,a[j]);
cq(k,1,j-1){
if(dis(o,a[k])>ri+eps){
tt(a[i],a[j],a[k]);
}
}
}
}
}
}
printf("%.10lf\n%.10lf %.10lf",ri,o.x,o.y);
return 0;
}


${\Huge\color{Salmon}{习题}}$（话说可以算成双倍经验）

P2533 [AHOI2012]信号塔
P1742 最小圆覆盖

posted @ 2018-09-12 07:24  enceladus  阅读(220)  评论(0编辑  收藏