#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const double PI = 3.14159265358979;
const int maxn = 1e3+4;
struct node
{
double x, y;
double rad;
}p[maxn], tp[maxn];
bool cmp1(node a, node b)
{
if(a.y == b.y) return a.x < b.x;
return a.y < b.y;
}
bool cmp2(node a, node b)
{
if(a.rad == b.rad) return a.x < b.x;
return a.rad < b.rad;
}
double rad_point(node a, node b)
{
return atan2((b.y-a.y), (b.x-a.x));
}
double dist_2point(node a, node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool tp_3point(node a, node b, node c)
{
double m = (b.x-a.x)*(c.y-a.y) - (c.x-a.x)*(b.y-a.y);
if(m > 0) return false;
if(m < 0 || m == 0) return true;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int n;
double r;
while(scanf("%d%lf", &n, &r) != EOF)
{
for(int i = 0; i < n; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
sort(p, p+n, cmp1);
for(int i = 0; i < n; i++) p[i].rad = rad_point(p[0], p[i]);
sort(p+1, p+n, cmp2);
tp[0] = p[0];
tp[1] = p[1];
tp[2] = p[2];
int top = 2;
for(int i = 3; i < n; i++)
{
while(top >= 1 && tp_3point(tp[top-1], tp[top], p[i])) top--;
tp[++top] = p[i];
}
top++;
double dist = 0;
for(int i = 0; i < top; i++) dist += dist_2point(tp[i%top], tp[(i+1)%top]);
double round = 2.0*PI*r;
printf("%.0lf\n", dist+round);
}
}
poj1113 凸包
最新推荐文章于 2020-05-03 23:27:33 发布
本文介绍了一个使用C++实现的几何计算程序,该程序通过定义结构体和多种比较函数来处理点集,包括计算点之间的角度、距离以及判断三点是否构成凸角等操作。通过对点集进行两次排序,最终计算出所有点构成的凸包周长加上圆的周长。
摘要由CSDN通过智能技术生成