poj 1113wall (凸包)

poj 1113wall (凸包)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define LL long long
#define M 1002
#define DEBUG puts("It's here!")
#define INF 1<<29
#define PI acos(-1.0)
#define CLS(x,v) memset(x,v,sizeof(x))
#define FOR(i,w,n)  for(int i=(w);i<=(n);++i)


struct point
{
    int x,y;
    void input()
    {
        scanf("%d%d",&x,&y);
    }
    point() {}
    point(int vx,int vy)
    {
        x=vx;
        y=vy;
    }
    point operator -(const point &b)
    {
        return  point(x-b.x,y-b.y);
    }
} p[M];
int cross(point a,point b )
{
    return a.x*b.y-a.y*b.x;
}
double dist(point a)
{
    return sqrt(1.0*a.x*a.x+a.y*a.y);
}
int cmp(point a,point b)
{
    int ret=cross(a-p[0],b-p[0]);
    if(ret==0)return dist(a-p[0])>dist(b-p[0]);
    else return ret>0;
}
int st[M],cnt;
int n,L;
void graham()
{
    int k=0,i;
    for(i=1; i<n; i++)
        if(p[i].x<p[k].x||(p[i].x==p[k].x&&p[i].y<p[k].y))
        {
            k=i;
        }
    swap(p[0],p[k]);
    sort(p+1,p+n,cmp);
    cnt=0;i=3;
    st[cnt]=0;
    st[++cnt]=1;
    st[++cnt]=2;
    while(i<n)
    {
        while(cnt>1&&cross(p[st[cnt]]-p[st[cnt-1]],p[i]-p[st[cnt]])<0)
            cnt--;
        st[++cnt]=i++;
    }
    st[++cnt]=0;
    double ans=0.0;
    for(i=1; i<=cnt; i++)
    {  // printf("-->%d %d\n",p[st[i]].x,p[st[i]].y);
        ans+=dist(p[st[i]]-p[st[i-1]]);
    }
    printf("%.0lf\n",ans+2*PI*L);
}
int main()
{
    while(~scanf("%d%d",&n,&L))
    {
        for(int i=0; i<n; i++)
        {
            p[i].input();
        }
        graham();
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值