主要是看边界的情况,因为他说最边上的距离不能超过L这就意味着拐角处外面的城墙应该是属于弧状的。
这样最后的结果就会是凸包周长加上
2
Π
L
2ΠL
2ΠL
套一下板子就好了。
ac code
#include <bits/stdc++.h>
#include <iostream>
#include<algorithm>
#include <cstdio>
#include <cmath>
#define re register int
#define int long long
#define inf 0x3f
using namespace std;
const int N=1e5+5;
int n,top,ans;
struct Point{
double x,y;
}point[N],stk[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 cross(Point a,Point b,Point c){
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
void find_miny(){
Point tmp=point[0];
int flag=0;
for(int i=1;i<n;i++){
if(point[i].y<tmp.y||(point[i].y==tmp.y&&point[i].x<tmp.x)){
tmp=point[i];
flag=i;
}
}
if(flag) swap(point[0],point[flag]);
}
bool cmp(Point a,Point b){
double n=cross(point[0],a,b);
if(n>0||(n==0&&dis(point[0],a)>dis(point[0],b))) return true;
return false;
}
void Graham(){
top=-1;
stk[++top]=point[0]; stk[++top]=point[1];
for(int i=2;i<n;i++){
while(top&&cross(stk[top-1],stk[top],point[i])<0) top--;
stk[++top]=point[i];
}
}
void solve()
{
double l;
cin>>n>>l;
top=0;
memset(stk,0,sizeof(stk));
memset(point,0,sizeof(point));
for(int i=0;i<n;i++){
cin>>point[i].x>>point[i].y;
}
find_miny();
sort(point+1,point+n,cmp);
Graham();
stk[++top]=point[0];
// for(int i=0;i<=top;i++)
// {
// cout<<stk[i].x<<" "<<stk[i].y<<endl;
// }
double fans=2.0*l*acos(-1);
for(int i=0;i<top;i++)
{
fans+=dis(stk[i],stk[i+1]);
}
if(n==1)
{
cout<<0<<endl;
return;
}
if(top==2)
{
printf("%.0f\n",fans/2);
return;
}
printf("%.0f\n",fans);
}
signed main() {
solve();
return 0;
}