holiday/8.10/I-Wall/main.cpp
2022-08-12 16:49:09 +08:00

74 lines
1.4 KiB
C++

//参考别人的
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
const double pi=acos(-1.00),eps = 1e-8;//pi3.14~
const int N=1005,inf=0x3f3f3f3f;
int q[N],n;
struct Point{
double x,y;
Point () {}//无参的构造函数,及初始化、赋初值
Point (double xx,double yy) :x(xx),y(yy) {}
Point friend operator - (Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
double friend operator ^ (Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
bool friend operator < (Point a,Point b)
{
if(a.y==b.y ) return a.x<b.x;
return a.y<b.y;
}
}p[N];
int sign(double d)
{
if(fabs(d)<eps) return 0;
return d>0? 1:-1;
}
double dist(Point a,Point b)
{
Point c=a-b;
return sqrt(c.x*c.x+c.y*c.y);//CE double
}
bool cmp(Point a,Point b)
{
int s=sign((a-p[1])^(b-p[1]));
if(s>0||(s==0&&dist(a,p[1])<dist(b,p[1])))return 1;
else return 0;
}
double Graham()
{
sort(p+1,p+n+1);
sort(p+1,p+1+n,cmp);
int top=3;
q[1]=1,q[2]=2,q[3]=3;
for(int i=4;i<=n;i++)
{
while(top>1&&sign((p[q[top]]-p[q[top-1]])^(p[i]-p[q[top]]))<=0){
top--;
}
q[++top]=i;
}
double res=0;
for(int i=1;i<top;i++)
{
res+=dist(p[q[i]],p[q[i+1]]);
}
return res+dist(p[q[1]],p[q[top]]);
}
int main()
{
int l;
scanf("%d%d",&n,&l);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);//&!!!
}
printf("%d",(int)(Graham()+pi*2*l+0.5));//(int)()记得加括号
return 0;
}