前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >POJ 1113 Wall(思维 计算几何 数学)

POJ 1113 Wall(思维 计算几何 数学)

作者头像
attack
发布2019-03-04 16:17:05
4240
发布2019-03-04 16:17:05
举报

题意

题目链接

给出平面上n个点的坐标。你需要建一个围墙,把所有的点围在里面,且围墙距所有点的距离不小于l。求围墙的最小长度。 n小于等于10^5

Sol

首先考虑如果没有l的限制,那么显然就是凸包的长度。

现在了距离的限制,那么显然原来建在凸包上的围墙要向外移动\(l\)的距离,同时会增加一些没有围住的位置

因为多边形的外交和为360,再根据补角的性质,画一画图就知道这一块是一个半径为\(l\)的圆。

因为总答案为凸包周长 + \(2 \pi l\)

代码语言:javascript
复制
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN = 1e5 + 10;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, top;
struct Point {
    double x, y;
    Point operator - (const Point &rhs) const {
        return {x - rhs.x, y - rhs.y};
    }
    Point operator + (const Point &rhs) const {
        return {x + rhs.x, y + rhs.y};
    }
    double operator ^ (const Point &rhs) const {
        return x * rhs.y - y * rhs.x;
    }
    bool operator < (const Point &rhs) const {
        return x == rhs.x ? y < rhs.y : x < rhs.x;
    }
}p[MAXN], q[MAXN];
template<typename A> A sqr(A x) {
    return x * x;
}
double dis(Point a, Point b) {
    return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}
void insert(Point now) {
    while(top > 1 && ((q[top] - q[top - 1]) ^ (now - q[top - 1])) < 0) top--;   
    q[++top] = now; 
}
int main() {
    N = read(); double L = read();
    for(int i = 1; i <= N; i++) p[i].x = read(), p[i].y = read();
    sort(p + 1, p + N + 1);
    q[top = 1] = p[1];
    for(int i = 2; i <= N; i++) insert(p[i]);
    for(int i = N - 1; i >= 1; i--) insert(p[i]);
    double ans = 0;
    for(int i = 1; i < top; i++) ans += dis(q[i], q[i + 1]);
    ans += 2 * acos(-1) * L + 0.5;
    printf("%d\n", (int) ans);
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-02-14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题意
  • Sol
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档