1 条题解

  • 0
    @ 2026-1-28 21:54:04
    #include <bits/stdc++.h>//超时52分
    using namespace std;
    
    using ll = long long;
    
    struct P {
        ll x, y;
        /* int pos() const {
            if (y < 0) return -1;
            if (y == 0 && 0 <= x) return 0;
            return 1;
        }
        bool operator<(P r) const {
            if (pos() != r.pos()) return pos() < r.pos();
            return 0 < (x * r.y - y * r.x);
        } */
        bool operator<(P r) const {
            return atan2(y,x) < atan2(r.y,r.x);
        }
    };
    
    int main() {
        int n;
        scanf("%d", &n);
        vector<P> ps(n);
        for (int i = 0; i < n; i++) {
            scanf("%lld %lld", &ps[i].x, &ps[i].y);
        }
        sort(ps.begin(), ps.end());
        for (auto p: ps) {
            printf("%lld %lld\n", p.x, p.y);
        }
        /* ll x,y;
        while(cin>>x>>y){
            P p{x,y};
            printf("%0.5lf\n", atan2(p.x,p.y)/3.1415926535*180);
        }    */
        return 0;
    }
    
    
    #include <iostream>
    #include <vector>
    #include <algorithm>
    
    using namespace std;
    using uint = unsigned int;
    using ll = long long;
    
    struct P {
        ll x, y;
        int pos() const {
            if (y < 0) return -1;
            if (y == 0 && 0 <= x) return 0;
            return 1;
        }
        bool operator<(P r) const {
            if (pos() != r.pos()) return pos() < r.pos();
            return 0 < (x * r.y - y * r.x);
        }
    };
    
    int main() {
        int n;
        scanf("%d", &n);
        vector<P> ps(n);
        for (int i = 0; i < n; i++) {
            scanf("%lld %lld", &ps[i].x, &ps[i].y);
        }
        stable_sort(ps.begin(), ps.end());
        for (auto p: ps) {
            printf("%lld %lld\n", p.x, p.y);
        }
        return 0;
    }
    
    
    • 1

    *【计算几何】点的角排序 Sort Points by Argument

    信息

    ID
    3327
    时间
    100ms
    内存
    1024MiB
    难度
    10
    标签
    递交数
    8
    已通过
    1
    上传者