1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| #include <cstdio> #include <cmath> #include <ctime> #include <algorithm>
struct Point { double x; double y; Point(double x=0,double y=0):x(x),y(y){} }; struct Circle { Point center; double radius_square; Circle(const Point & point,double radius):center(point),radius_square(radius){} Circle():center(Point(0,0)),radius_square(0){}
}; Circle circumcircle(const Point & p1,const Point & p2,const Point & p3); Circle circumcircle(const Point & p1,const Point & p2); bool contains(const Circle & circle,const Point & point);
Circle minSpanCircle(const Point & p1,const Point & p2,const Point * points,int k); Circle minSpanCircle(const Point & p,const Point * points,int k); Circle minSpanCircle(const Point * points,int k);
Point points[100005]; using namespace std;
int main() { int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf%lf",&points[i].x,&points[i].y); srand(unsigned(time(0))); random_shuffle(points,points+n); Circle circle = minSpanCircle(points,n); printf("%.10f\n%.10f %.10f",sqrt(circle.radius_square),circle.center.x,circle.center.y); return 0; }
Circle circumcircle(const Point & p1,const Point & p2) { double radius_square = 0.25*((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); return Circle(Point((p1.x+p2.x)/2,(p1.y+p2.y)/2),radius_square); } Circle circumcircle(const Point & p1,const Point & p2,const Point & p3) { double t1 = p1.x + p2.x; double t2 = p1.x - p2.x; double t3 = p3.x + p2.x; double t4 = p3.x - p2.x; double t5 = p1.y + p2.y; double t6 = p1.y - p2.y; double t7 = p3.y + p2.y; double t8 = p3.y - p2.y;
double t = 2.0*(t2*t8-t4*t6); double t9 = t1*t2+t5*t6; double t10 = t3*t4+t7*t8;
double x = (t9*t8-t10*t6)/t; double y = (t10*t2-t9*t4)/t; double radius_square = (p1.x-x)*(p1.x-x)+(p1.y-y)*(p1.y-y); return Circle(Point(x,y),radius_square); }
Circle minSpanCircle(const Point & p1,const Point & p2,const Point * points,int k) { Circle circle = circumcircle(p1,p2); for(int i=0;i<k;i++) { if(!contains(circle,points[i])) circle = circumcircle(p1,p2,points[i]); } return circle; } Circle minSpanCircle(const Point & p,const Point * points,int k) { if(k <= 0) return Circle(p,0); Circle circle = circumcircle(p,points[0]);
for(int i=1;i<k;i++) { if(!contains(circle,points[i])) circle = minSpanCircle(p,points[i],points,i); } return circle; } Circle minSpanCircle(const Point * points,int k) { if(k <= 0) return Circle(); else if(k <= 1) return Circle(points[0],0); else if(k <= 2) return circumcircle(points[0],points[1]);
Circle circle = circumcircle(points[0],points[1]); for(int i=2;i<k;i++) { if(!contains(circle,points[i])) circle = minSpanCircle(points[i],points,i); } return circle; } bool contains(const Circle & circle,const Point & point) { return (point.x-circle.center.x)*(point.x-circle.center.x) + (point.y-circle.center.y)*(point.y-circle.center.y) <= circle.radius_square; }
|