poj1113 Wall【凸包】

74 篇文章 0 订阅
33 篇文章 0 订阅

题目链接:http://poj.org/problem?id=1113
题意:给你一个多边形,让你在距离他x的地方围一圈有弧形的矩形,让你求这个矩形的周长
解析:其实就是凸包边长,加上半径为x的圆的面积

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
const int maxn = 1e5+100;
const double eps = 1e-10;
const double pi = acos(-1.0);
struct point
{
    double x,y;
    point() {}
    point(double _x,double _y)
    {
        x = _x;
        y = _y;
    }
    bool operator < (const point &b) const
    {
        if(y==b.y)
            return x<b.x;
        return y<b.y;
    }
}a[maxn],ans[maxn];
double x_mul(point p0,point p1,point p2)
{
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double dis(point p1,point p2)
{
    return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
}
bool cmp(point t1,point t2)
{
    double tmp = x_mul(a[0],t1,t2);
    if(tmp==0)
        return dis(a[0],t1)<dis(a[0],t2);
    else
        return tmp>0;
}
double graham(int n)
{
    sort(a,a+n);
    sort(a+1,a+n,cmp);
    ans[0] = a[0];
    ans[1] = a[1];
    ans[2] = a[2];
    int top = 2;
    for(int i=3;i<n;i++)
    {
        while(top>=2&&x_mul(ans[top-1],ans[top],a[i])<0)
            top--;
        ans[++top] = a[i];
    }
    double res = 0;
    for(int i=0;i<top;i++)
        res += dis(ans[i],ans[i+1]);
    res += dis(ans[top],ans[0]);
    return res;
}
int main(void)
{
    int n,x;
    scanf("%d %d",&n,&x);
    for(int i=0;i<n;i++)
        scanf("%lf %lf",&a[i].x,&a[i].y);
    double sum = graham(n)+2.0*x*pi;
    printf("%.0f\n",sum);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值