标签:
#include<stdio.h> #include<math.h> #include<algorithm> using namespace std; const int MAXN = 107; const double EPS = 1e-8; struct Point { double x, y; int id; Point(double x=0, double y=0):x(x),y(y){} Point operator - (const Point &tmp) const{ return Point(x-tmp.x, y-tmp.y); } double operator *(const Point &tmp) const{ return x*tmp.x + y*tmp.y; } double operator ^(const Point &tmp) const{ return x*tmp.y - y*tmp.x; } }; double Dist(Point a, Point b) { return sqrt((a-b)*(a-b)); } Point p[MAXN]; int ki; bool cmp(Point a, Point b) { double t = (a-p[ki]) ^ (b-p[ki]); if(fabs(t) < EPS) return Dist(p[ki], a) < Dist(p[ki], b); return t > EPS; } int main() { int T; scanf("%d", &T); while(T--) { int i, N; scanf("%d", &N); for(int i=0; i<N; i++) { scanf("%d%lf%lf", &p[i].id, &p[i].x, &p[i].y); if(p[i].y < p[0].y || (p[i].y==p[0].y && p[i].x < p[0].x)) swap(p[i], p[0]); } ki = 0; for(i=1; i<N; i++, ki++) { sort(p+i, p+N, cmp); } printf("%d", N); for(i=0; i<N; i++) printf(" %d", p[i].id); printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/liuxin13/p/4794089.html