poj2007

输入一个凸包且没有三点共线,输入的第一个点始终是(0,0),从(0,0)开始逆时针输出所有点

极角排序输出即可。

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

const double eps = 1e-8;

struct Point {
   double x, y;
} p[55];

int dblcmp(double k) {
   if (fabs(k) < eps) return 0;
   return k > 0 ? 1 : -1;
}

double multi(Point p0, Point p1, Point p2) {
   return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}

bool cmp(const Point& a, const Point& b) {
   return dblcmp(multi(p[0], a, b)) > 0;
}

int main()
{
    int n = 0, i;

    while (scanf ("%lf%lf", &p[n].x, &p[n].y) != EOF) n++;
    sort(p+1, p+n, cmp);
    for (i = 0; i < n; i++)
        printf ("(%.0lf,%.0lf)\n", p[i].x, p[i].y);

    return 0;
}



你可能感兴趣的:(struct)