1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| #include <bits/stdc++.h> using namespace std; using ll = long long;
const int maxn = 100 + 5;
struct Point { int id, x, y; } ps[maxn];
bool vis[maxn]; int n;
int cross( Point a, Point b, Point c ) { return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); }
int dist( Point a, Point b ) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); }
void solve( ) { cin >> n; memset( vis, 0, sizeof( vis ) );
int start = 1; for( int i = 1; i <= n; i ++ ) { cin >> ps[i].id >> ps[i].x >> ps[i].y; if( ps[i].y < ps[start].y ) start = i; }
Point cur = ps[start]; vector<int> ans;
vis[start] = 1; ans.push_back( cur.id ); for( int i = 1; i < n; ++ i ) { int nxt = -1;
for( int j = 1; j <= n; ++ j ) { if( vis[j] ) continue; if( nxt == -1 ) { nxt = j; continue; }
int cp = cross( cur, ps[nxt], ps[j] );
if( cp < 0 ) { nxt = j; } else if( cp == 0 ) { if( dist( cur, ps[j] ) > dist( cur, ps[nxt] ) ) nxt = j; } }
vis[nxt] = 1; cur = ps[nxt]; ans.push_back( cur.id ); }
cout << ans.size( ) << " "; for( int i = 0; i < ans.size( ); ++ i ) { cout << ans[i] << " "; } cout << '\n'; }
int main( ) { int _t = 1; cin >> _t; while( _t -- ) { solve( ); } return 0; }
|