1. 程式人生 > >Andrew求凸包

Andrew求凸包

bool cmp(P p1,P p2){
    if(p1.x<p2.x) return 1;
    if(p1.x>p2.x) return 0;
    return p1.y<p2.y;
}
void andrew(){
    sort(s,s+n,cmp);0開始排序
    for(int i = 0;i < n;i ++){
        while(top>1&&cs(ch[top-2],ch[top-1],s[i])<=0) top --;
        ch[top++] = s[i];
    }
    int
k = top; for(int i = n-2;i >= 0;i --){ while(top>k&&cs(ch[top-2],ch[top-1],s[i])<=0) top --; ch[top++] = s[i]; } if(n>1) top --; }