转自https://www.cnblogs.com/jbelial/archive/2011/08/05/2128625.html
![](https://img-blog.csdn.net/20180324104256284?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpcnVpNzYxMA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
![](https://img-blog.csdn.net/20180324104315937?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpcnVpNzYxMA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
double Multiply(POINT p1 , POINT p2 , POINT p3) // 叉积
{
return ( (p2.x - p1.x)*(p3.y - p1.y) - (p2.y - p1.y)*(p3.x - p1.x) ) ;
}
for ( i = 3 ; i <= n ; ++ i )
{
while (Multiply(result[top - 1] , result[top] , tree[i]) <= 0 )
top -- ; //出栈
result[top + 1].x = tree[i].x ;
result[top + 1].y = tree[i].y ;
top ++ ;
}
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef class Node{
public:
LL x,y;
bool operator<(Node a)
{
if(x==a.x) return y<a.y;
else return x<a.x;
}
}node;
node a[1005],b[1005];
int k=0;
node findmax1(node t1,node t2)
{
int i=0,j,max=0;
while(a[i].x<t1.x) i++;
for(i;a[i].x<=t2.x;i++)
{
if(a[i].y<0) continue;
long long aa=t1.x*t2.y+a[i].x*t1.y+t2.x*a[i].y-a[i].x*t2.y-t2.x*t1.y-t1.x*a[i].y;
if(abs(aa)>max)
{
max=abs(aa);
j=i;
}
}
return a[j];
}
node findmax2(node t1,node t2)
{
int i=0,j,max=0;
while(a[i].x<t1.x) i++;
for(i;a[i].x<=t2.x;i++)
{
if(a[i].y>0) continue;
long long aa=t1.x*t2.y+a[i].x*t1.y+t2.x*a[i].y-a[i].x*t2.y-t2.x*t1.y-t1.x*a[i].y;
if(abs(aa)>max)
{
max=abs(aa);
j=i;
}
}
return a[j];
}
void Convex_Hullup(node t1,node t2)
{
node t3;
t3=findmax1(t1,t2);
if(t3.x!=t2.x||t3.y!=t2.y)
{b[++k].x=t3.x;
b[k].y=t3.y;
}
Convex_Hullup(t1,t3);
Convex_Hullup(t3,t2);
}
void Convex_Hulldown(node t1,node t2)
{
node t3;
t3=findmax2(t1,t2);
if(t3.x!=t2.x||t3.y!=t2.y)
{b[++k].x=t3.x;
b[k].y=t3.y;
}
Convex_Hulldowm(t1,t3);
Convex_Hulldowm(t3,t2);
}
int dis(node t1,node t2)
{
return (t1.x-t2.x)*(t1.x-t2.x)+(t1.y-t2.y)*(t1.y-t2.y);
}
int main()
{
int num,n,d;
cin>>num;
while(num--)
{
cin>>n>>d;
k=0;
for(int i=0;i<n;i++)
{
cin>>a[i].x>>a[i].y;
}
sort(a,a+n);
Convex_Hullup(a[0],a[n-1]);
Convex_Hulldown(a[0],a[n-1]);
double sum=0;
for(int i=1;i<=k;i++)
{
sum+=sqrt(dis(b[i],b[i-1]));
}
}
return 0;
}