POJ 2007 Scrambled Polygon(凸包,极角排序)

POJ 2007 Scrambled Polygon(凸包,极角排序)

思路:没仔细看题,没想到居然是固定源点,我还以为说不固定,打乱,搞半天。。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const double pi = acos(-1.0);
double maxx = -1e18;
struct Point {
    int x, y;
    Point(int x = 0, int y = 0):x(x),y(y){}
};
typedef Point Vector;
Vector operator - (Point A, Point B){
    return Vector(A.x-B.x, A.y-B.y);
}
bool operator < (const Point& a, const Point& b){
    if(a.x == b.x)
        return a.y < b.y;
    return a.x < b.x;
}
double Cross(Vector v0, Vector v1) {
    return v0.x*v1.y - v1.x*v0.y;
}


Point c;

bool cmp2(Point a,Point b)
{
    c.x = 0;
    c.y = 0;

    if(Cross(b-a,c-a)==0)//计算叉积,函数在上面有介绍,如果叉积相等,按照X从小到大排序
        return a.x<b.x;
    else return Cross(b-a,c-a)>0;
}
Point p[100],tubao[100];
int main()
{
    int cnt =0;
    int x, y;
    while(scanf("%d%d",&p[cnt].x, &p[cnt].y)!=EOF)
    {
        //cout<<p[cnt].x<<p[cnt].y<<endl;
        cnt++;

    }
    //cout<<cnt<<endl;

    sort(p+1,p+cnt,cmp2);
    for(int i = 0;i<cnt;i++)
    {
        printf("(%d,%d)\n",p[i].x, p[i].y);
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值