holiday/8.10/I-Wall/main.cpp

82 lines
1.6 KiB
C++
Raw Normal View History

2022-08-12 16:44:44 +08:00
//<2F>ο<EFBFBD><CEBF><EFBFBD><EFBFBD>˵<EFBFBD>
2022-08-12 15:37:34 +08:00
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include<stack>
using namespace std;
2022-08-12 16:44:44 +08:00
const double pi=acos(-1.00),eps = 1e-8;//pi3.14~
const int N=1005,inf=0x3f3f3f3f;
2022-08-12 15:37:34 +08:00
double ans=0;
2022-08-12 16:44:44 +08:00
int q[N],n;
struct Point{
double x,y;
Point () {}//<2F>޲εĹ<CEB5><C4B9><EFBFBD><ECBAAF>,<2C><><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
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];
//stack<int>s;
2022-08-12 15:37:34 +08:00
int sign(double d)
{
if(fabs(d)<eps) return 0;
return d>0? 1:-1;
}
2022-08-12 16:44:44 +08:00
//double cross(double x1, double y1, double x2, double y2)
//{
// return x1 * y2 - x2 * y1;
//}
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)
2022-08-12 15:37:34 +08:00
{
2022-08-12 16:44:44 +08:00
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;
2022-08-12 15:37:34 +08:00
}
2022-08-12 16:44:44 +08:00
double Graham()
2022-08-12 15:37:34 +08:00
{
2022-08-12 16:44:44 +08:00
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]]);
2022-08-12 15:37:34 +08:00
}
int main()
{
2022-08-12 16:44:44 +08:00
int l,minn=1,f,ff,x0,x1,x2,y1,y2,y0;
2022-08-12 15:37:34 +08:00
scanf("%d%d",&n,&l);
for(int i=1;i<=n;i++)
{
2022-08-12 16:44:44 +08:00
scanf("%lf%lf",&p[i].x,&p[i].y);//&!!!
2022-08-12 15:37:34 +08:00
}
2022-08-12 16:44:44 +08:00
printf("%d",(int)(Graham()+pi*2*l+0.5));//(int)()<29>ǵü<C7B5><C3BC><EFBFBD><EFBFBD><EFBFBD>
2022-08-12 15:37:34 +08:00
return 0;
}