顺便整理出来一份自己看着比较顺眼的模板
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 1010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = 3.141592653;
const double inf = ~0u>>;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {} //构造函数 方便代码编写
}p[N],ch[N];
typedef Point pointt;
pointt operator + (Point a,Point b)
{
return Point(a.x+b.x,a.y+b.y);
}
pointt operator - (Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
pointt operator * (Point a,double b)
{
return Point(a.x*b,a.y*b);
}
pointt operator / (Point a,double b)
{
return Point(a.x/b,a.y/b);
}
bool operator < (const Point &a,const Point &b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
}
bool operator == (const Point &a,const Point &b)
{
return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
}
//求点积以及利用点积求长度和夹角的函数
double dot(Point a,Point b)
{
return a.x*b.x+a.y*b.y;
}
//叉积及叉积求面积
double cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
double dis(Point a)
{
return sqrt(dot(a,a));
}
double mul(Point p0,Point p1,Point p2)
{
return cross(p1-p0,p2-p0);
}
bool cmp(Point a,Point b)
{
if(dcmp(mul(p[],a,b))==)
return dis(a-p[])<dis(b-p[]);
else
return dcmp(mul(p[],a,b))>;
}
int Graham(int n)
{
int i,k = ,top = ;
Point tmp;
if(n<=)
{
for(i = ; i <= ; i++)
ch[i] = p[i];
return n+;
}
for(i = ; i <= n; i++)
{
if(p[i].y<p[k].y||(p[i].y==p[k].y&&p[i].x<p[k].x))
k = i;
}
if(k!=)
{
tmp = p[]; p[] = p[k]; p[k] = tmp;
}
sort(p+,p+n+,cmp);
ch[top++] = p[];
ch[top++] = p[];
ch[top++] = p[];
for(i = ; i <= n ;)
{
if(top<||mul(ch[top-],ch[top-],p[i])>)
{
ch[top++] = p[i++];
}
else top--;
}
return top;
}
int main()
{
int i,n,r;
while(scanf("%d%d",&n,&r)!=EOF)
{
for(i = ; i <= n ; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
int top = Graham(n);
ch[top] = p[];
double ma;
ma = *pi*r;
for(i = ; i < top ; i++)
{
ma += dis(ch[i]-ch[i+]);
}
printf("%.0f\n",ma);
}
return ;
}