POJ 2007 Scrambled Polygon(极角排序)

题目大意:按逆时针方向连接个点,并将其输出,第一个点为(0,0)。

题目思路:叉积排下序就好了

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
#define MAX 100005
#define PI acos(-1)

using namespace std;

struct node
{
    int x,y;
} point[MAX];

int Stuck[MAX],pos,cnt;

int Cross(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{
    return (x1-x2)*(y3-y4)-(x3-x4)*(y1-y2);
}

bool cmp(struct node A,struct node B)
{
    if(Cross(0,0,A.x,A.y,0,0,B.x,B.y)>=0)
        return true;
    return false;
}

int main()
{
    int x,y;
    cnt=0;
    while(scanf("%d%d",&x,&y)!=EOF)
    {
        point[cnt].x=x;
        point[cnt].y=y;
        cnt++;
    }
    sort(point+1,point+cnt,cmp);
    for(int i=0;i<cnt;i++)
        printf("(%d,%d)\n",point[i].x,point[i].y);
    return 0;
}
View Code

 

posted @ 2016-11-04 15:44  声声醉如兰  阅读(138)  评论(0编辑  收藏  举报