昨天看这题就在想怎么和最小圆覆盖结合一起,不过没信心写 = =。。
昨晚搜题解,有人发布官方标程了,还真是结合最小圆覆盖了。
我还是对最小圆覆盖理解不好啊。。。把我的改了改,就过了。
二者一起算,如果碰到在m那个集合里的点,如果在内部,就让它作为边界点即可。
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define FOR(i,s,t) for(int i=s; i<t; i++)
#define BUG puts("here!!!")
using namespace std;
const int MAX = 20010;
struct point {
double x,y;
bool f;
void get() { scanf("%lf%lf", &x, &y); }
};
point p[MAX];
const double eps = 1e-6;
bool dy(double x,double y) { return x > y + eps;} // x > y
bool xy(double x,double y) { return x < y - eps;} // x < y
bool dyd(double x,double y) { return x > y - eps;} // x >= y
bool xyd(double x,double y) { return x < y + eps;} // x <= y
bool dd(double x,double y) { return fabs( x - y ) < eps;} // x == y
double disp2p(point a,point b) // a b 两点之间的距离
{
return sqrt( ( a.x - b.x ) * ( a.x - b.x ) + ( a.y - b.y ) * ( a.y - b.y ) );
}
point circumcenter(point a,point b,point c)
{
point ret;
double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1*a1 + b1*b1)/2;
double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2*a2 + b2*b2)/2;
double d = a1 * b2 - a2 * b1;
ret.x = a.x + (c1*b2 - c2*b1)/d;
ret.y = a.y + (a1*c2 - a2*c1)/d;
return ret;
}
void min_cover_circle(point p[],int n,point &c,double &r)
{
random_shuffle(p,p+n);// #include <algorithm>
c = p[0]; r = 0;
for(int i=1; i<n; i++)
if( dy(disp2p(p[i],c),r) && p[i].f || xy(disp2p(p[i],c),r) && !p[i].f )
{
c = p[i];
r = 0;
for(int k=0; k<i; k++)
if( dy(disp2p(p[k],c),r) && p[k].f || xy(disp2p(p[k],c),r) && !p[k].f )
{
c.x = (p[i].x + p[k].x)/2;
c.y = (p[i].y + p[k].y)/2;
r = disp2p(p[k],c);
for(int j=0; j<k; j++)
if( dy(disp2p(p[j],c),r) && p[j].f || xy(disp2p(p[j],c),r) && !p[j].f )
{ // 求外接圆圆心,三点必不共线
c = circumcenter(p[i],p[k],p[j]);
r = disp2p(p[i],c);
}
}
}
}
int main()
{
int n, m;
while( ~scanf("%d%d", &n, &m) )
{
FOR(i, 0, n)
{
p[i].get();
p[i].f = true;
}
FOR(i, n, n+m)
{
p[i].get();
p[i].f = false;
}
point c; double r;
min_cover_circle(p, n+m, c, r);
printf("%.3lf %.3lf\n%.3lf\n", c.x, c.y, r);
}
return 0;
}