首页 > 技术文章 > 象限极角排序

tun117 2016-07-23 19:44 原文

struct Point
{
    int id;
    LL x,y;
    Point(){}
    Point(LL x,LL y):x(x),y(y){}
    void Read(){scanf("%I64d%I64d",&x,&y);}
    LL operator^(const Point P)const{return x*P.y-y*P.x;}
    Point operator-(const Point P)const{return Point(x-P.x,y-P.y);}
}me[10],mos[1050],tmp[1050];
int quad(Point a)
{
    if(a.x>0 && a.y>=0) return 1;
    if(a.x<=0 && a.y>0) return 2;
    if(a.x<0 && a.y<=0) return 3;
    if(a.x>=0 && a.y<0) return 4;
}

bool cmp(Point a,Point b)
{
    int l1=quad(a),l2=quad(b);
    if(l1==l2)
    {
        LL c=a^b;
        return c<0LL || (c==0LL && a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y);
    }
    return l1<l2;
}
bool Equal(Point a,Point b)
{
    int l1=quad(a),l2=quad(b);
    return l1==l2&&(a^b)==0;
}

 

推荐阅读