POJ 2007 Scrambled Polygon(几何)

题目链接:POJ 2007 Scrambled Polygon

给出的都是凸包上的点,那就不用求凸包了,直接排序输出就行了,注意不要排原点,WA了几次。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

const double eps = 1e-10;
const int MAX_N = 50 + 10;

struct Point
{
	int x, y;
	Point(int x=0, int y=0):x(x),y(y) { }
};

typedef Point Vector;

Vector operator + (const Vector& A, const Vector& B)
{
    return Vector(A.x+B.x, A.y+B.y);
}

Vector operator - (const Point& A, const Point& B)
{
    return Vector(A.x-B.x, A.y-B.y);
}

Vector operator * (const Vector& A, double p)
{
    return Vector(A.x*p, A.y*p);
}

bool operator < (const Point& a, const Point& b)
{
	return a.x < b.x || (a.x == b.x && a.y < b.y);
}


int Cross(const Vector& A, const Vector& B)
{
    return A.x*B.y - A.y*B.x;
}

Point p[MAX_N];

bool cmp(Point a, Point b)
{
    return Cross(p[0] - a, p[0] - b) > 0;
}

int main()
{
    //freopen("in.txt", "r", stdin);
    int x, y;
    int i = 0;
    while(scanf("%d%d", &x, &y) != EOF)
        p[i++] = Point(x, y);
    sort(p + 1, p + i, cmp);
    for(int j = 0; j < i; j++)
        printf("(%d,%d)\n", p[j].x, p[j].y);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值