P2533 [AHOI2012]信号塔

题目描述

P2533 [AHOI2012]信号塔_第1张图片

输入格式

img

输出格式

img

输入输出样例

输入 #1

5
1.200 1.200
2.400 2.400
3.800 4.500
2.500 3.100
3.900 1.300

输出 #1

2.50 2.85 2.10

说明/提示

队员是否在边界上的判断应该符合他到圆心的距离与信号塔接受半径的差的绝对值小于10^-6,最终结果保留2位整数。

30%:1<=N<=10000

70%:1<=N<=20000

100%:1<=N<=1e6

最小圆覆盖的模板题。。。看似\(O(n^3)\) 其实是\(O(n)\) 。。。。。。

#include
#include
#include
#include
using namespace std;
const int N = 1e6+100;
const double eps = 1e-6;
int n;
struct point{double x , y; } a[N] , o;
double r;
inline double dis(point A ,point B) { return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y)) ;}
int from[4];
int dcmp(double X) { return fabs(X) < eps ? 0 : (X < eps ? -1 : 1) ; }
bool include(point A) { return dcmp(dis(A , o) - r) <= 0; }

void build(point A , point B , point C)
{
    double 
    a = B.x - A.x , b = B.x + A.x ,
    c = B.y - A.y , d = B.y + A.y ,
    ap = C.x - A.x , bp = C.x + A.x ,
    cp = C.y - A.y , dp = C.y + A.y ;
    o.x = (ap * bp * c - cp * a * b + cp * dp * c - cp * c * d) / (ap * c - cp * a) / 2.0;
    o.y = (a * b - 2 * o.x * a + c * d) / c / 2.0;
    r = dis(o , A); return ;
}

int main()
{
    scanf("%d",&n);
    for(int i = 1 ; i <= n ; ++i) scanf("%lf%lf" , &a[i].x , &a[i].y);
    random_shuffle(a + 1 , a + 1 + n);
    o = a[1]; r = 0;
    for(int i = 2 ; i <= n ; ++i)
    {
        if(include(a[i])) continue;
        o = a[i]; r = 0;
        for(int j = 1 ; j < i ; ++j)
        {
            if(include(a[j])) continue;
            o.x = (a[i].x + a[j].x) * 0.5;
            o.y = (a[i].y + a[j].y) * 0.5;
            r = dis(o , a[j]);
            for(int k = 1 ; k < j ; ++k)
            {
                if(include(a[k])) continue;
                build(a[i] , a[j] , a[k]);
            }
        }
    }
    printf("%.2f %.2f %.2f" , o.x , o.y , r);
    return 0;
}

你可能感兴趣的:(P2533 [AHOI2012]信号塔)