POJ 2007 Scrambled Polygon

Posted on 2017-01-20 10:33  ziliuziliu  阅读(180)  评论(0编辑  收藏  举报

虽然A了但是完全不懂这题在干什么。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 105
using namespace std;
struct point
{
    int x,y;
    point (int x,int y):x(x),y(y) {}
    point () {}
    friend point operator - (point x,point y)
    {
        return point(x.x-y.x,x.y-y.y);
    }
    friend int operator * (point x,point y)
    {
        return x.x*y.y-x.y*y.x;
    }
}p[maxn];
int ps,qs,tot=0,top=0,stack[maxn];
bool vis[maxn];
bool cmp1(point x,point y)
{
    if (x.y!=y.y) return x.y<y.y;
    return x.x<y.x;
}
bool cmp2(point x,point y)
{
    return (x-p[1])*(y-p[1])>=0;
}
int main()
{
    while (scanf("%d%d",&ps,&qs)!=EOF)
        p[++tot]=point(ps,qs);
    sort(p+2,p+tot+1,cmp2);
    int ret=-1;
    for (int i=1;i<=tot;i++) if ((!p[i].x) && (!p[i].y)) {ret=i;break;}
    printf("(0,0)\n");
    for (int i=ret+1;i!=ret;i=i%tot+1)
        printf("(%d,%d)\n",p[i].x,p[i].y);
    return 0;
}