【凸包 Graham法 极角排序】poj 2007 Scrambled Polygon

Link:http://poj.org/problem?id=2007

Graham法求凸包(O(Nlog2N))

/* 极角排序 */
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const int N = 100;
const double eps = 1e-6;
struct Point
{
    double x,y;
};
Point a[N];
//是否严格左转,共线不算(叉乘)
double xmult(Point a,Point b,Point c)   //(ca)×(cb)
{
    return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
// sort排序函数
bool cmp(const Point &a, const Point &b)//逆时针排序
{
    Point origin;
    // 设置原点
    origin.x = origin.y = 0;
    return xmult(origin,b,a)<eps;
}

int main()
{
    int n=0;
    while(scanf("%lf%lf",&a[n].x,&a[n].y)!=EOF)
        ++n;
    // 极角排序,第一个空过去
    sort(a+1,a+n,cmp);
    for(int i=0; i<n; ++i)
        printf("(%.0lf,%.0lf)\n",a[i].x,a[i].y);
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值