POJ2007 Scrambled Polygon

PS: 此题可以用凸包做,也可以用极角排序,关键是理解排序原理,题目说不会出现三点共线的情况。(Window 64bit %I64d, Linux %lld)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

struct point {
    long long x, y;
    point(long long x=0, long long y=0):x(x),y(y) {}
};
point S;

point operator - (point A, point B) {
    return point(A.x-B.x, A.y-B.y);
}
double Cross(point A, point B) {
    return A.x*B.y - A.y*B.x;
}

bool cmp(point A, point B) {
    return Cross(A-S, B-S)>0;
}
vector<point> v;
int main()
{
    point t;
    scanf("%I64d%I64d", &S.x, &S.y);
    v.clear();
    while(scanf("%I64d%I64d", &t.x, &t.y)!=EOF) {
        v.push_back(t);
    }
    sort(v.begin(), v.end(), cmp);
    printf("(0,0)\n");
    int len = v.size();
    for(int i = 0; i < len; i++) {
        printf("(%I64d,%I64d)\n", v[i].x, v[i].y);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值