zoukankan      html  css  js  c++  java
  • poj1113 Wall

    题目描述:

    vjudge

    POJ

    题解:

    答案就是凸包周长+2πL。

    代码:

    #include<cmath>
    #include<cstdio>
    #include<vector>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int N = 1050;
    const double Pi = acos(-1.0);
    struct Point
    {
        double x,y;
        Point(){}
        Point(double x,double y):x(x),y(y){}
        Point operator + (const Point&a)const{return Point(x+a.x,y+a.y);}
        Point operator - (const Point&a)const{return Point(x-a.x,y-a.y);}
        double operator * (const Point&a)const{return x*a.x+y*a.y;}
        double operator ^ (const Point&a)const{return x*a.y-y*a.x;}
        bool operator < (const Point&a)const{return x!=a.x?x<a.x:y<a.y;}
    };
    typedef Point Vector;
    int n;
    double L;
    Point p[N],s[N];
    double lth(const Vector&a){return sqrt(a*a);}
    int build()
    {
        sort(p+1,p+1+n);
        int tl = 0;
        for(int i=1;i<=n;i++)
        {
            while(tl>1&&((s[tl]-s[tl-1])^(p[i]-s[tl-1]))<=0)tl--;
            s[++tl]=p[i];
        }
        int k = tl;
        for(int i=n-1;i>=1;i--)
        {
            while(tl>k&&((s[tl]-s[tl-1])^(p[i]-s[tl-1]))<=0)tl--;
            s[++tl]=p[i];
        }
        if(tl!=1)tl--;
        return tl;
    }
    int main()
    {
        scanf("%d%lf",&n,&L);
        for(int i=1;i<=n;i++)
            scanf("%lf%lf",&p[i].x,&p[i].y);
        int m = build();
        double ans=0.0;
        for(int i=1;i<m;i++)
            ans+=lth(s[i+1]-s[i]);
        ans+=lth(s[1]-s[m]);
        printf("%.0lf
    ",ans+Pi*L*2);
        return 0;
    }
    View Code
  • 相关阅读:
    LeetCode 100. 相同的树(Same Tree) 2
    LeetCode 680. 验证回文字符串 Ⅱ(Valid Palindrome II) 1
    MySQL索引操作
    MySQL数据库的一些方法使用
    Anaconda安装新模块
    源码下载
    mongodb内建角色
    windows server 2008开启共享文件设置
    MySQL配置说明
    MySQL的连接数
  • 原文地址:https://www.cnblogs.com/LiGuanlin1124/p/10982942.html
Copyright © 2011-2022 走看看