297522026-06-19 18:44:21miszorimarciZárt poligon készítése **cpp17Elfogadva 100/10026ms1868 KiB
#include <bits/stdc++.h>

using namespace std;

struct Point {
    long long x, y;
    int id;
};

long long fordul(Point a, Point b, Point c) {
    return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}

long long dist(Point a, Point b) {
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;

    vector<Point> p(n);
    int st = 0;

    for (int i = 0; i < n; ++i) {
        cin >> p[i].x >> p[i].y;
        p[i].id = i + 1;
        if (p[i].y < p[st].y || 
           (p[i].y == p[st].y && p[i].x < p[st].x)) {
            st = i;
        }
    }

    swap(p[0], p[st]);
    Point p0 = p[0];

    sort(p.begin() + 1, p.end(), [&](const Point& a, const Point& b) {
        long long cp = fordul(p0, a, b);
        if (cp != 0) {
            return cp > 0;
        }
        return dist(p0, a) < dist(p0, b);
    });
    int i = n - 1;
    while (i > 1 && fordul(p0, p[i], p[i-1]) == 0) {
        i--;
    }
    reverse(p.begin() + i, p.end());

    for (int j = 0; j < n; ++j) {
        cout << p[j].id << (j == n - 1 ? "" : " ");
    }
    cout << "\n";

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base100/100
1Elfogadva2/22ms316 KiB
2Elfogadva2/22ms316 KiB
3Elfogadva2/22ms316 KiB
4Elfogadva2/22ms316 KiB
5Elfogadva2/23ms568 KiB
6Elfogadva4/44ms564 KiB
7Elfogadva4/44ms564 KiB
8Elfogadva4/44ms620 KiB
9Elfogadva4/44ms756 KiB
10Elfogadva4/44ms564 KiB
11Elfogadva6/69ms916 KiB
12Elfogadva6/610ms820 KiB
13Elfogadva6/610ms820 KiB
14Elfogadva6/69ms836 KiB
15Elfogadva6/610ms908 KiB
16Elfogadva8/825ms1844 KiB
17Elfogadva8/826ms1852 KiB
18Elfogadva8/825ms1868 KiB
19Elfogadva8/825ms1868 KiB
20Elfogadva8/826ms1844 KiB