zoukankan      html  css  js  c++  java
  • POJ 1113 Wall(思维 计算几何 数学)

    题意

    题目链接

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

    Sol

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

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

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

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

    #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
    ", (int) ans);
    }
    
  • 相关阅读:
    基于IDEA+Maven+SpringMVC的入门web程序分析(一)
    Spring之路----chapter03 高级装配
    Spring之路---chapter02装配Bean
    Spring之路----Chapter01 Spring之旅
    实用网址-项目的创建、Idea打开Maven项目、Idea打开Eclipse项目
    Git之路-2017年9月8日14:37:01
    Redis入门指南-笔记-进阶
    DenyHosts 阻止SSH暴力攻击
    某cms最新版前台RCE漏洞(无需任何权限)2020-03-15
    通过Joomla的两次RCE漏洞看session反序列化
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/10375835.html
Copyright © 2011-2022 走看看