给定n个点可以形成一个多边形,按照逆时针的顺序输出这n个点。
考虑用叉乘比较极角
struct Point { int x, y; Point(int _x = 0,int _y = 0): x(_x),y(_y){} Point operator -(const Point& b)const { return Point(x - b.x, y - b.y); } double operator ^(const Point& b)const { return x * b.y - y * b.x; } }; int cross(Point A, Point B, Point C) { return (B - A) ^ (C - A); } vector<Point> p; bool cmp(const Point a,const Point b) { Point z = Point(); return cross(z, b, a) < 0; } int main() { int xx, yy; while (~scanf("%d%d", &xx, &yy)) { p.push_back(Point(xx, yy)); } sort(p.begin() + 1, p.end(),cmp); for (int i = 0; i < p.size(); i++) printf("(%d,%d) ", p[i].x, p[i].y); }