题解 : 可以画图验证加上推导一下就会发现这个题的答案就是凸包的周长加上外面圆的周长。剩下的就是模版了
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
const double eps = 1e-8;
const int maxn = 1005;
const double INF = 1e15 + 7;
const double PI = 3.1415926;
int n;
double r;
struct point {
double x,y;
}p[maxn],tu[maxn];
point init;
double dist (point a,point b) {
return sqrt ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double cross (double x1,double y1,double x2,double y2) {
return x1 * y2 - x2 * y1;
}
bool cmp (point a,point b) {
if (fabs(cross(a.x - init.x, a.y - init.y, b.x - init.x, b.y - init.y)) < eps) {
return dist(a, init) < dist(b, init);
}
else
return cross(a.x - init.x, a.y - init.y, b.x - init.x, b.y - init.y) > 0;
}
int main () {
while (scanf ("%d%lf",&n,&r) != EOF) {
double mix = 0,miy = INF;
int pos = 1;
for (int i = 1;i <= n; ++ i) {
scanf ("%lf%lf",&p[i].x,&p[i].y);
if (miy > p[i].y) {
miy = p[i].y;
pos = i;
mix = p[i].x;
}
else if (fabs (miy - p[i].y) < eps) {
if (mix > p[i].x) {
mix = p[i].x;
pos = i;
}
}
}
swap (p[1],p[pos]);
init = p[1];
sort (p + 2,p + n + 1,cmp);
tu[1] = p[1],tu[2] = p[2],tu[3] = p[3];
int tot = 3;
for (int i = 4;i <= n; ++ i) {
while (tot >= 3) {
point p1,p2,p3;
p1 = tu[tot];
p2 = tu[tot - 1];
p3 = p[i];
if (cross(p1.x - p2.x,p1.y - p2.y , p3.x-p1.x, p3.y - p1.y) < 0) tot --;
else break;
}
tu[++tot] = p[i];
}
double res = 0;
for (int i = 1;i <= tot; ++ i) {
if (i != tot) {
res += dist(tu[i], tu[i + 1]);
}
else res += dist(tu[1], tu[tot]);
}
res += 2 * r * PI;
int ans = floor(res + 0.5);
printf ("%d\n",ans);
}
return 0;
}