加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

bzoj 1670 护城河的挖掘 凸包

发布时间:2020-12-14 03:16:24 所属栏目:大数据 来源:网络整理
导读:#includecmath #includecstdio #includeiostream #includealgorithm #define maxn 5005 using namespace std ; struct point{ double x,y; point(){} point( double x1, double y1){x=x1,y=y1;} double operator %( const point A) const { return x*A.y-y*A
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm> 
#define maxn 5005
using namespace std;
struct point
{
    double x,y;
    point(){}
    point(double x1,double y1){x=x1,y=y1;}
    double operator %(const point &A) const
    {   return x*A.y-y*A.x;}
    double operator *(const point &A) const
    {   return x*A.x+y*A.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);}
};
point p[maxn],S[maxn];int top;
bool cmp(point A,point B)
{return A.x<B.x||(A.x==B.x&&A.y<B.y);}

double pw(double x){return x*x;}
double Cross(point A,point B,point C)
{return (B-A)%(C-A);}
double dis(point A,point B)
{return sqrt(pw(A.x-B.x)+pw(A.y-B.y));}

    int n;
double ans;
void get_Tubao()
{
    sort(p+1,p+n+1,cmp);
    for(int i=1;i<=n;i++)
    {
        while(top>1&&Cross(S[top-1],p[i],S[top])<=0) top--;
        S[++top]=p[i];
    }
    int j=top;
    for(int i=n;i>=1;i--)
    {
        while(top>j&&Cross(S[top-1],S[top])<=0) top--;
        S[++top]=p[i];
    }
    for(int i=1;i<top;i++)
        ans+=dis(S[i],S[i+1]);
    ans+=dis(S[1],S[top]);
}
int main()
{
    scanf("%d",&n);
    int x,y;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&x,&y);
        p[i].x=(double)x;
        p[i].y=(double)y;
    }
    get_Tubao();
    printf("%.2lf",ans);
    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读