tubao pku1113
View Code
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 1001
const double pi=acos(-1.0);
struct point
{
int x,y;
}node[N];
int s[N];
int top;
int cmp(point a,point b)
{
if(a.y==b.y)
return a.x<b.x;
return a.y<b.y;
}
double chaji(point p0,point p1,point p2)
{
return ((p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x));
}
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void tubao(int n)
{
int i,temp;
sort(node,node+n,cmp);
top=-1;
s[++top]=0;
s[++top]=1;
for(i=2;i<n;i++)
{
while(top>=1&&chaji(node[s[top-1]],node[i],node[s[top]])>=0 )
top--;
s[++top]=i;
}
temp=top;
s[++top]=n-2;
for(i=n-3;i>=0;i--)
{
while(top>=temp+1&&chaji(node[s[top-1]],node[i],node[s[top]])>=0)
top--;
s[++top]=i;
}
}
int main()
{
int i,n,l;
double ans;
while(scanf("%d%d",&n,&l)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d%d",&node[i].x,&node[i].y);
tubao(n);
ans=0;
for(i=0;i<top;i++)
ans+=dis(node[s[i]],node[s[i+1]]);
ans+=2*pi*l;
printf("%.0lf",ans);
}
return 0;
}
模板题