B - Scrambled Polygon POJ - 极角排序

  • B - Scrambled Polygon

  •  POJ - 2007 
  • 按照与第一个点的夹角排序即可,
  • #include
    #include
    #include
    using namespace std;
    #define maxn 105
    #define PR 1e-6
    struct node
    {
        int x,y;
    } p[maxn];
    double l,ans;
    int n,stk[maxn],top;
    double cha(node p0,node p1,node p2)
    {
        return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
    }
    bool cmp(node a,node b)
    {
        return ((cha(p[1],a,b)))>0;
    }
    int main()
    {
        n=1;
        while(~scanf("%d%d",&p[n].x,&p[n].y))
            n++;
        sort(p+2,p+n,cmp);
        int i;
        for(i = 1; i 

     

你可能感兴趣的:(计算几何)