半径R覆盖最多点

struct point {
    double x, y;
};
point p[N];
struct alpha {
    double v;
    bool flag;
    bool friend operator <(const alpha &a, const alpha &b) {
        return a.v < b.v;
    }
} alp[N * 2];
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 n,s;
bool judge(double R) {
    int ans = 0;
    double theta, phi, dist;
    for(int i = 0; i < n; i++) {
        int k = 0;
        for(int j = 0; j < n; j++) {
            if(i == j) continue;
            dist = dis(p[i], p[j]);
            if(dist > 2.0 * R)
                continue;
            theta = atan2(p[j].y - p[i].y, p[j].x - p[i].x);
            if(theta < 0)
                theta += 2 * pi;
            phi = acos(dist / (2.0 * R));
            alp[k].v = theta - phi + 2 * pi;
            alp[k].flag = true;
            alp[k + 1].v = theta + phi + 2 * pi;
            alp[k + 1].flag = false;
            k += 2;
        }
        sort(alp, alp + k);
        int sum = 0;
        for(int j = 0; j < k; j++) {
            if(alp[j].flag)
                sum ++;
            else
                sum --;
            if(sum > ans)
                ans = sum;
        }
    }
    return ans + 1 >= s;//ans+1 为最多点
}

 

posted on 2018-09-08 17:10  scau_bi  阅读(237)  评论(0编辑  收藏  举报

导航