• 最小圆覆盖 gym-102006 I


    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define PLL pair<LL, LL>
    #define PLI pair<LL, int>
    #define PII pair<int, int>
    #define SZ(x) ((int)x.size())
    #define ull unsigned long long
    using namespace std;
    
    const int N = 2e5 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 + 7;
    const double eps = 1.1e-4;
    const  double PI = acos(-1);
    
    struct Point {
        double x, y;
        Point(double x = 0, double y = 0) : x(x), y(y) { }
    };
    typedef Point Vector;
    
    int dcmp(double x) {
        if(fabs(x) < eps) return 0;
        else return x < 0 ? -1 : 1;
    }
    
    Point operator + (Vector A, Vector B) {return Point(A.x + B.x, A.y + B.y);}
    Point operator - (Vector A, Vector B) {return Point(A.x - B.x, A.y - B.y);}
    Point operator * (Vector A, double p) {return Point(A.x * p, A.y * p);}
    Point operator / (Vector A, double p) {return Point(A.x / p, A.y / p);}
    bool operator < (const Vector &A, const Vector &B) {return A.y < B.y || (A.y == B.y && A.x < B.x);}
    bool operator == (const Vector &A, const Point &B) {return dcmp(A.x - B.x) == 0 && dcmp(A.y - B.y) == 0;}
    double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;}
    double Length(Vector A) {return sqrt(Dot(A, A));}
    double Angle(Vector A, Vector B) {return acos(Dot(A, B) / Length(A) / Length(B));}
    double Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;}
    double Area2(Point A, Point B, Point C) {return Cross(B - A, C - A);}
    
    Vector Rotate(Vector A, double rad) {
        return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
    }
    
    double dist(const Point& a, const Point &b) {
        return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
    }
    
    int n;
    double r, R;
    Point p[N];
    
    Point GetCircleCenter(Point A, Point B, Point C) {
        Point o;
        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;
        o.x=A.x+(c1*b2-c2*b1)/d;
        o.y=A.y+(a1*c2-a2*c1)/d;
        return o;
    }
    
    void MinPointCoverByCircle(Point *p, int n, Point &o, double &r) {
        random_shuffle(p, p+n);
        o = p[0], r = 0;
        for(int i = 1; i < n; i++) {
            if(dist(p[i], o) > r + eps) {
                o = p[i]; r = 0;
                for(int j = 0; j < i; j++) {
                    if(dist(p[j], o) > r + eps) {
                        o.x = (p[i].x+p[j].x)/2;
                        o.y = (p[i].y+p[j].y)/2;
                        r = dist(p[j], o);
                        for(int k = 0; k < j; k++) {
                            if(dist(p[k], o) > r + eps) {
                                o = GetCircleCenter(p[i], p[j], p[k]);
                                r = dist(p[i], o);
                            }
                        }
                    }
                }
            }
        }
    }
    
    int main() {
    //    freopen("robots.in", "r", stdin);
        int T; scanf("%d", &T);
        while(T--) {
            scanf("%d%lf%lf", &n, &R, &r); n++;
            p[0] = Point(0, 0);
            for(int i = 1; i < n; i++) {
                double x, y; scanf("%lf%lf", &x, &y);
                p[i] = p[i-1] + Point(x, y);
            }
            sort(p, p+n);
            n = unique(p, p+n)-p;
            Point o;
            MinPointCoverByCircle(p, n, o, r);
            printf("%.12f %.12f
    ", -o.x, -o.y);
        }
        return 0;
    }
    /*
    */
  • 相关阅读:
    [Tips]:SQL server 2005 Create Assembly Failed
    [Tips]:JavaScript命名空间
    卓有成效的程序员之笔记与实践
    Culture List
    Windows Azure CloudBlobContainer.CreateIfNotExist : One of the request inputs is out of range.
    Failed to add FS to collection at ResourceService.SetResource in Map 3D 2013
    ADO.net DataTable 和Amazon SimpleDB的相互转换
    对MapGuide/AIMS进行压力测试StressTest并进行性能优化
    AIMS/MapGuide API二次开发从入门到精通视频课程系列3
    创建Visual Studio项目模版向导的几篇参考文章
  • 原文地址:https://www.cnblogs.com/CJLHY/p/10197821.html
Copyright © 2020-2023  润新知