Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 31181 | Accepted: 10517 |
Description
![](https://i-blog.csdnimg.cn/blog_migrate/795547457e5e67245c9908aff158362e.gif)
Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements.
The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.
Input
Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.
Output
Sample Input
9 100 200 400 300 400 300 300 400 300 400 400 500 400 500 200 350 200 200 200
Sample Output
1628
Hint
Source
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
#define PI acos(-1.0)
int N,L,k;
struct point{
int x,y;
point (){};
point (int x,int y):x(x),y(y) {}
point mi (point b)
{
point cnt;
cnt.x=x-b.x;
cnt.y=y-b.y;
return cnt;
}
int det(point b)
{
return x*b.y-y*b.x;
}
double dis(point b)
{
return sqrt(double((x-b.x)*(x-b.x)+(y-b.y)*(y-b.y)));
}
};
point ps[2000];
point qs[4000];
bool cmp(const point a,const point b)
{
if (a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
void convex()
{
sort(ps , ps + N, cmp);
k=1;
qs[0]=ps[0];
qs[1]=ps[1];
for (int i=2;i<N;i++)
{
while(k>1&&((qs[k-1].mi(qs[k-2])).det(ps[i].mi(qs[k-1]))<=0)) k--;
qs[k++]=ps[i];
}
for (int i=N-2,t=k;i>=0;i--)
{
while(k>t&&((qs[k-1].mi(qs[k-2])).det(ps[i].mi(qs[k-1]))<=0)) k--;
qs[k++]=ps[i];
}
return ;
}
void slove()
{
double ans=0;
for (int i=0;i<k-1;i++)
{
ans+=(qs[i]).dis(qs[i+1]);
}
ans+=2*acos(-1.0)*L;
printf("%.0f\n",ans);
return;
}
int main()
{
while(scanf("%d%d",&N,&L)!=EOF)
{
for (int i=0;i<N;i++)
{
int a,b;
scanf("%d%d",&a,&b);
point cnt;
cnt.x=a;cnt.y=b;
ps[i]=cnt;
}
convex();
slove();
}
return 0;
}