POJ 2007 极角排序

简介:

题意:给出一个凸包的顶点,以第一次输入进去的点按逆时针方向排序。

看到有人说是凸包题,题意已经明确是凸包的顶点所以没有必要再用Graham模板。利用叉积的性质对极角进行排序就可以。

#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct point
{
    int x,y;
};
int Direction(point a,point b,point c)
{
    return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
point t,data[51];
bool cmp(point a,point b)
{
    if(Direction(t,a,b)>=0)
        return 1;
    return 0;
}
int main()
{
    int n=0,x,y;
    while(~scanf("%d%d",&x,&y))
        data[n].x=x,data[n].y=y,++n;
    t.x=data[0].x,t.y=data[0].y;
    sort(data+1,data+n,cmp);
    for(int i=0; i<n; i++)
        printf("(%d,%d)\n",data[i].x,data[i].y);
    return 0;
}



目录
相关文章
|
9月前
POJ-2245-Lotto
POJ-2245-Lotto
45 0
|
人工智能 机器学习/深度学习
POJ 1804
题目:http://poj.org/problem?id=1804 大意:给你一串数字,排序。求出最少的交换次数  \ 我用归并做的 #include #include using namespace std; int aa[500010],bb[500010]; long lon...
710 0
|
人工智能 BI
POJ-1003-hangover
Description How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length.
774 0
|
人工智能
POJ 1936 All in All
Description You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way.
802 0
poj题目分类
http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html
780 0