提交时间:2024-04-26 17:48:56

运行 ID: 28580

#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5009; int n; ll a[N], b[N]; ll calc(int i, int j, int k) { return a[i] * b[j] + a[j] * b[k] + a[k] * b[i]; } namespace sub1 { bool chk() { for (int i = 1; i <= n; i++) { if (a[i] > 1e3 || b[i] > 1e3) return 0; } return n > 50 && n <= 1000; } int p[N], vis[N]; void dfs(int u) { if (u > 3) { int i = p[u - 3], j = p[u - 2], k = p[u - 1]; if (calc(i, j, k) < calc(k, j, i)) return; } if (u > n) { for (int i = 1; i <= n; i++) printf("%d ", p[i]); exit(0); } for (int i = 1; i <= n; i++) { if (vis[i]) continue; vis[i] = 1, p[u] = i; dfs(u + 1); vis[i] = 0; } } void Main() { dfs(1); printf("-1\n"); } } int p[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld%lld", &a[i], &b[i]); } sub1::Main(); fclose(stdin); fclose(stdout); return 0; }