bzoj 1337 最小圆覆盖

时间:2021-05-15 14:37:29
 /**************************************************************
Problem: 1337
User: idy002
Language: C++
Result: Accepted
Time:4 ms
Memory:2372 kb
****************************************************************/ #include <cstdio>
#include <cmath>
#include <algorithm>
#define line(a,b) ((b)-(a))
#define eps 1e-10
#define N 100010
using namespace std; int sg( double x ) { return (x>-eps)-(x<eps); }
struct Vector {
double x, y;
Vector( double x=, double y= ):x(x),y(y){}
Vector operator+( const Vector &b ) const { return Vector(x+b.x,y+b.y); }
Vector operator-( const Vector &b ) const { return Vector(x-b.x,y-b.y); }
Vector operator*( double b ) const { return Vector(x*b,y*b); }
Vector operator/( double b ) const { return Vector(x/b,y/b); }
double operator^( const Vector &b ) const { return x*b.y-y*b.x; }
double len() { return sqrt(x*x+y*y); }
Vector nor() { return Vector(-y,x); }
};
typedef Vector Point;
Point inter( Point p, Vector u, Point q, Vector v ) {
return p+u*((line(p,q)^v)/(u^v));
}
struct Circle {
Point o;
double r;
Circle(){}
Circle( Point a ):o(a),r(){}
Circle( Point a, Point b ) {
o = (a+b)/;
r = (a-b).len()/;
}
Circle( Point a, Point b, Point c ) { // ab^bc != 0
Point p=(a+b)/, q=(b+c)/;
Vector u=(a-b).nor(), v=(b-c).nor();
o = inter(p,u,q,v);
r = (o-a).len();
}
bool contain( Point a ) {
return sg( (a-o).len() - r ) <= ;
}
}; int n;
Point pts[N]; int main() {
scanf( "%d", &n );
for( int i=; i<=n; i++ ) {
double x, y;
scanf( "%lf%lf", &x, &y );
pts[i] = Point(x,y);
}
random_shuffle( pts+, pts++n );
Circle c = Circle(pts[]);
for( int i=; i<=n; i++ ) {
if( c.contain(pts[i]) ) continue;
c = Circle(pts[i]);
for( int j=; j<i; j++ ) {
if( c.contain(pts[j]) ) continue;
c = Circle(pts[i],pts[j]);
for( int k=; k<j; k++ ) {
if( c.contain(pts[k]) ) continue;
c = Circle(pts[i],pts[j],pts[k]);
}
}
}
printf( "%.3lf\n", c.r );
}

题解见bzoj 1336