计算几何入门3--poj1113Wall

19 篇文章 0 订阅
13 篇文章 0 订阅

裸凸包……直接上代码……

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=10000+10;
const double eps=1e-12;
int n,l,top=0;
double ans;
struct point{
    double x,y;
}p[maxn];
point sta[maxn];

bool cmp(const point &a,const point &b){
    return a.x<b.x||(a.x==b.x&&a.y<b.y);
}

int comp(double x){
    return fabs(x)<eps?0:x>0?1:-1;
}

double crossx(point a,point b,point c){//ab x ac 
    return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}

double cal(point a,point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

int main(){
    while (~scanf("%d%d",&n,&l)){
        for (int i=1;i<=n;++i)
            scanf("%lf%lf",&p[i].x,&p[i].y);
        memset(sta,0,sizeof(sta));
        sort(p+1,p+1+n,cmp); top=0; ans=0;                                       
        sta[++top]=p[1]; sta[++top]=p[2];
        for (int i=3;i<=n;++i){
            while (top>1&&comp(crossx(sta[top-1],sta[top],p[i]))<0) top--;
            sta[++top]=p[i];
        }
        int mid=top; sta[++top]=p[n]; sta[++top]=p[n-1];
        for (int i=n-2;i>=1;i--){
            while (top>mid&&comp(crossx(sta[top-1],sta[top],p[i]))<0) top--;
            sta[++top]=p[i];
        }
        for (int i=2;i<=top;++i) 
            ans+=cal(sta[i],sta[i-1]);
        //for (int i=1;i<=top;++i) printf("%lf %lf\n",sta[i].x,sta[i].y);
        //ans+=cal(sta[1],sta[top]);
        double Sy=2*l*3.1415926535; ans+=Sy;
        printf("%.0f\n",ans);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值