这样不好。。。一天到晚就搞搞水题。。。
这题WA点就是凸包如果只有一个点的时候,输出0,两个点的时候输出距离
以上
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const double eps=1e-10;
int dcmp(double x)
{
if(fabs(x)<eps) return 0;
return x<0?-1:1;
}
struct Point
{
double x,y;
Point(){}
Point(double x,double y):x(x),y(y){}
bool operator==(const Point& rhs)const
{
return dcmp(x-rhs.x)==0 && dcmp(y-rhs.y)==0;
}
bool operator<(const Point& rhs)const
{
return dcmp(x-rhs.x)<0 || (dcmp(x-rhs.x)==0 && dcmp(y-rhs.y)<0);
}
};
typedef Point Vector;
Vector operator-(Point A,Point B)
{
return Vector(A.x-B.x,A.y-B.y);
}
double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
double Length(Point A,Point B)
{
return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
int ConvexHull(Point *p,int n,Point *ch)//求凸包
{
sort(p,p+n);
n=unique(p,p+n)-p;
int m=0;
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];
}
int 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;
}
const int maxn=100+4;
int n;
Point p[maxn],poly[maxn];
int main()
{
while(scanf("%d",&n)&&n){
for(int i=0;i<n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
int m=ConvexHull(p,n,poly);
if(m==1){printf("0\n");continue;}
if(m==2){printf("%.2f\n",Length(poly[0],poly[1]));continue;}
double ans=0;
for(int i=0;i<m;i++){
ans+=Length(poly[i],poly[(i+1)%m]);
}
printf("%.2f\n",ans);
}
return 0;
}