• 【POJ 1113】Wall


    http://poj.org/problem?id=1113

    夏令营讲课时的求凸包例题,据说是PKUSC2015的一道题

    我WA两次错在四舍五入上了(=゚ω゚)ノ

    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    double Pi = acos(-1);
    const int N = 1003;
    
    struct Point {
    	double x, y;
    	Point(double _x = 0, double _y = 0) : x(_x), y(_y) {}
    	bool operator < (const Point &A) const {
    		return x == A.x ? y < A.y : x < A.x;
    	}
    } a[N], tu[N];
    int top = 1;
    
    Point operator + (Point a, Point b) {return Point(a.x + b.x, a.y + b.y);}
    Point operator - (Point a, Point b) {return Point(a.x - b.x, a.y - b.y);}
    Point operator * (Point a, double x) {return Point(a.x * x, a.y * x);}
    Point operator / (Point a, double x) {return Point(a.x / x, a.y / x);}
    
    double Dot(Point a, Point b) {return a.x * b.x + a.y * b.y;}
    double Cross(Point a, Point b) {return a.x * b.y - a.y * b.x;}
    double sqr(double x) {return x * x;}
    double dis(Point a, Point b) {return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));}
    
    int dcmp(double x) {return fabs(x) < 1e-8 ? 0 : (x < 0 ? -1 : 1);}
    
    void mktb(int n) {
    	tu[1] = a[1];
    	for(int i = 2; i <= n; ++i) {
    		while (top > 1 && dcmp(Cross(a[i] - tu[top], tu[top] - tu[top - 1])) <= 0) --top;
    		tu[++top] = a[i];
    	}
    	int k = top;
    	for(int i = n - 1; i >= 1; --i) {
    		while (top > k && dcmp(Cross(a[i] - tu[top], tu[top] - tu[top - 1])) <= 0) --top;
    		tu[++top] = a[i];
    	}
    }
    
    int main() {
    	int n, l;
    	scanf("%d%d", &n, &l);
    	for(int i = 1; i <= n; ++i) scanf("%lf%lf", &a[i].x, &a[i].y);
    	
    	sort(a + 1, a + n + 1);
    	
    	mktb(n);
    	
    	double ret = 2.0 * l * Pi;
    	for(int i = 1; i < top; ++i)
    		ret += dis(tu[i], tu[i + 1]);
    	
    	printf("%d
    ", (int) (ret + 0.5));
    	return 0;
    }
    

    复习模板~

  • 相关阅读:
    climbing-stairs
    binary-tree-inorder-traversal
    search-insert-position
    balanced-binary-tree
    Java 接口工厂案例
    Java 接口案例
    Java 抽象类
    unique-paths
    maximum-subarray
    php修改文件夹下的所以图片png改为jpg,也可以作为修改为其他格式的方法
  • 原文地址:https://www.cnblogs.com/abclzr/p/5671522.html
Copyright © 2020-2023  润新知