标签:
这个的题意是绕一圈使得圈上所有点到原来的点的距离都大于等于l。求最短周长。
平移一下,几何乱搞?发现这个弧线刚好是个圆。
convexhull。。这个我抄的版也不知道是什么算法但是好像靠谱。研究凸包的一个算法。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct point
{
int x,y;
point(int x=0,int y=0):x(x),y(y){}
};
typedef point vector;
point ch[1010],p[1010];
const double pi=atan(1.0)*4;
int n;
int cross(vector a,vector b)
{
return a.x*b.y-a.y*b.x;
}
vector operator + (vector a,vector b)
{
return vector(a.x+b.x,a.y+b.y);
}
vector operator - (vector a,vector b)
{
return vector(a.x-b.x,a.y-b.y);
}
vector operator * (vector a,double p)
{
return vector(a.x*p,a.y*p);
}
vector operator / (vector a,double p)
{
return vector(a.x/p,a.y/p);
}
bool operator < (point a,point b)
{
return a.x<b.x||(a.x==b.x && a.y<b.y);
}
double dis(point a,point b)
{
return sqrt(1.0*(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int convexhull()
{
sort(p,p+n);
int m=0,k;
for (int i=0;i<n;i++)
{
while (m>1 && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
m--;
ch[m++]=p[i];
}
k=m;
for (int i=n-2;i>=0;i--)
{
while (m>k && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
m--;
ch[m++]=p[i];
}
if (n>1) m--;
return m;
}
int main()
{
int l;
while (scanf("%d%d",&n,&l)==2)
{
for (int i=0;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
int m=convexhull();
double ans=0;
for (int i=1;i<m;i++)
ans=ans+dis(ch[i-1],ch[i]);
ans=ans+dis(ch[0],ch[m-1]);
ans=ans+2.0*pi*l;
printf("%d\n",int(ans+0.5));
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/ziliuziliu/p/5055674.html