This article is made by Jason-Cow.
Welcome to reprint.
But please post the article's address.
利用一下叉积和栈
1 int Andrew(D*R,int n,D*A){ 2 int m=0; 3 sort(R+1,R+n+1);//for(int i=1;i<=n;i++)cout<<R[i].x<<" "<<R[i].y<<endl; 4 for(int i=1;i<=n;i++){ 5 while(m>=2 && Cross(A[m]-A[m-1],R[i]-A[m-1])<=0)m--; 6 A[++m]=R[i]; 7 } 8 int k=m; 9 for(int i=n-1;i>=1;i--){ 10 while(m>k && Cross(A[m]-A[m-1],R[i]-A[m-1])<=0)m--; 11 A[++m]=R[i]; 12 } 13 return n>1?m-1:m; 14 }