pseudo-code: graham scan algorithm
input:a set of pointss=
select the rightmost lowest point p0 ins.
sortsangularly about p0 as a center.
for ties, discard the closer points.
let p[n] be the sorted array of points.
push p[0]=p0 and p[1] onto a stackw.
while i < n
else
pop the top point pt1 off the stack
}output:w= the convex hull ofs.
**:凸包問題的幾種演算法,包括graham scan 演算法
這個演算法其實也很好想通的。
第一步:找到y座標最小的點p0;
第二步:以p0為原點,對所有的點按逆時針順序排序;
第三步:逐步迭代,加入邊界點。(畫出一條邊,如果乙個新的邊更靠左,則加入,否則不加入)。
#include#include#includeusing namespace std;
const int num=50005;
int n;
struct point
points[num],output[num];
inline int ccw(point p1,point p2,point p3) //交叉乘積
inline int dis(point p1,point p2) //距離
int cmp(const void *po1,const void *po2) //排序用的比較函式
else if(temp<0)
else }
int maxdist( )
/*else if(temp==0)
*/else
}int maxd=0;
for(int i=0;i<=top;i++) //計算邊界點之間的距離 }
printf("%d\n",maxd);
return maxd;
}int main()
{ freopen("input.txt","r",stdin);
while( scanf("%d",&n)!=eof) //輸入
{ for(int i=0;i
poj2187 凸包直徑模板
include include include include using namespace std define inf 50005 struct node node point inf int n,s inf top double cross node a,node b,node c doub...
Poj2187 凸包求最大距離
凸包 暴力求解,注意n 0,和n 1的情況 include include include include include include include define maxn 50000 10 using namespace std typedef struct point point int ...
poj 2187 凸包 最大點對距
題目大意就是最大點對距,最大點對距的兩端點一定是凸包頂點,所以找出形成凸包所需要的最少頂點,然後遍歷找出最大點對距。對凸包演算法的詳細講解 include include using namespace std struct point point vertex 500000 res 500000 ...