题目链接: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;
}