题意:凸包周长+一个完整的圆周长。因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆。
模板题,之前写的Graham模板不对,WR了很多发。。。。POJ上的AC代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define clc(a,b) memset(a,b,sizeof(a))
#define eps 1e-8
#define PI acos(-1.0)
typedef long long LL;
const int mod=;
const int inf=0x3f3f3f3f;
const int MAXN=;
using namespace std; const int N = ; int top;
struct point
{
double x;
double y;
} p[N], Stack[N]; double dis(point A, point B)
{
return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
} double crossProd(point A, point B, point C)
{
return (B.x-A.x)*(C.y-A.y) - (B.y-A.y)*(C.x-A.x);
} int cmp(const void *a, const void *b)
{
point *c = (point *)a;
point *d = (point *)b;
double k = crossProd(p[], *c, *d);
if (k< || !k && dis(p[], *c)>dis(p[], *d))
return ;
return -;
} void Graham(int n)
{
double x = p[].x;
double y = p[].y;
int mi = ;
for (int i=; i<n; ++i)
{
if (p[i].x<x || (p[i].x==x && p[i].y<y))
{
x = p[i].x;
y = p[i].y;
mi = i;
}
}
point tmp = p[mi];
p[mi] = p[];
p[] = tmp;
qsort(p+, n-, sizeof(point), cmp);
p[n] = p[];
Stack[] = p[];
Stack[] = p[];
Stack[] = p[];
top = ;
for (int i=; i<=n; ++i)
{
while (crossProd(Stack[top-], Stack[top], p[i])<= && top>=) --top;
Stack[++top] = p[i];
}
} int main()
{
int n, l;
while (scanf("%d%d", &n, &l) != EOF)
{
for (int i=; i<n; ++i)
{
scanf ("%lf%lf", &p[i].x, &p[i].y);
}
Graham(n);
double ans=;
for(int i=;i<top;i++)
{
ans+=dis(Stack[i], Stack[i+]);
}
ans += PI * (l + l);
printf ("%d\n", (int)(ans+0.5));
}
return ;
}