现在的位置: 首页 > 综合 > 正文

poj 3525 Most Distant Point from the Sea,半平面交 + 二分

2018年12月24日 ⁄ 综合 ⁄ 共 487字 ⁄ 字号 评论关闭

Most Distant Point from the Sea


二分离海距离, 按距离平移有向线段(“收缩”多边形),然后半平面求交验证

int main()
{
    int n;
    while(~scanf("%d", &n),n)
    {
        vector<Point> p, v, normal;
        for(int i=0; i<n; ++i) {
            int x, y;
            scanf("%d%d", &x, &y);
            p.push_back(Point(x,y));
        }
        for(int i=0; i<n; ++i){
            v.push_back(p[(i+1)%n] - p[i]);
            normal.push_back(Normal(v[i]));
        }
        double l = 0, r = 20000, mid;
        while(r-l > eps){
            vector<Line> L;
            mid = l + (r-l)/2;
            for(int i=0; i<n; ++i) L.push_back(Line(p[i]+normal[i]*mid, v[i]));
            if(HalfplaneIntersection(L).empty()) r = mid;
            else l = mid;
        }
        printf("%.6f\n", l);
    }
    return 0;
}

抱歉!评论已关闭.