poj 1113 凸包

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <cmath>
using namespace std;
const int maxn=1e5+10;
const double PI=acos(-1.0);
struct Point  { double x,y; Point(double x=0,double y=0):x(x),y(y) {};    };
typedef Point Vector;
Vector operator - (Point  A, Point  B){ return Vector(A.x-B.x, A.y-B.y); } // 向量生成
double dis(Point A,Point B) { return sqrt( (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y) );  }
double Cross(Vector B, Vector A) { return A.x*B.y-A.y*B.x;   }  // 叉积
Point pa[maxn];
Point pt[maxn];
bool up(Point a,Point b)
{
    if(a.x!=b.x) return a.x<b.x;
    return a.y<b.y;
}
int main()
{
    int n,r; scanf("%d %d",&n,&r);
    for(int i=0;i<n;i++) scanf("%lf %lf",&pa[i].x,&pa[i].y);
    sort(pa,pa+n,up);
    int m=0;
    for(int i=0;i<n;i++)
    {
        while(m>1 && Cross(pt[m-1]-pt[m-2],pa[i]-pt[m-2])<=0) m--;
        pt[m++]=pa[i];
    }
    int k=m;
    for(int i=n-2;i>=0;i--)
    {
        while(m>k && Cross(pt[m-1]-pt[m-2],pa[i]-pt[m-2])<=0) m--;
        pt[m++]=pa[i];
    }
    if(n>1) m--;
    double ans=0;
    for(int i=1;i<m;i++) ans+=dis(pt[i],pt[i+1]); ans+=dis(pt[m],pt[1]);
    //cout<<ans<<"  "<<PI<<endl;
    ans+=PI*r*2;
    printf("%.0f\n",ans);
    return 0;
}

 

转载于:https://www.cnblogs.com/Andromeda-Galaxy/p/10655646.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值