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

bzoj1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 计算

发布时间:2020-12-14 02:46:01 所属栏目:大数据 来源:网络整理
导读:裸凸包,上个模板。 #include iostream#include cstring#include cmath#include cstdio#include algorithmusing namespace std;#define maxn 10000struct node{ double x,y;}p[maxn];int s[maxn],top,n;double ans;double sqr(double x){ return x*x;}double
裸凸包,上个模板。
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define maxn 10000
struct node
{
    double x,y;
}p[maxn];
int s[maxn],top,n;
double ans;
double sqr(double x)
{
    return x*x;
}
double dis(node a,node b)
{
    return sqr(a.x-b.x)+sqr(a.y-b.y);
}
inline node operator-(node a,node b)
{
    node t;t.x=a.x-b.x;t.y=a.y-b.y;return t;
}
inline double operator*(node a,node b)
{
    return a.x*b.y-a.y*b.x;
}
bool cmp(node a,node b)
{
    double t=(a-p[1])*(b-p[1]);
    if(t==0)return dis(p[1],a)<dis(p[1],b);
    return t>0;
}
void graham()
{
    int t=1;
    for(int i=2;i<=n;i++)
        if(p[i].y<p[t].y||(p[i].y==p[t].y&&p[i].x<p[t].x))t=i;
    swap(p[1],p[t]);
    sort(p+2,p+n+1,cmp);
    top=2;
    s[1]=1;s[2]=2;
    for(int i=3;i<=n;i++)
    {
        for(;(p[s[top]]-p[s[top-1]])*(p[i]-p[s[top-1]])<=0;top--);
        top++;s[top]=i;
    }
    s[top+1]=1;
    for(int i=1;i<=top;i++)
        ans+=sqrt(dis(p[s[i]],p[s[i+1]]));
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lf%lf",&p[i].x,&p[i].y);
    }
    graham();
    printf("%.2lfn",ans);
    return 0;
}

(编辑:李大同)

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

    推荐文章
      热点阅读