4 条题解

  • 0
    @ 2025-3-2 20:37:37
    #include <iostream>
    #include <vector>
    #include <algorithm>
    
    // 定义点的结构体
    struct Point {
        int x;
        int y;
    };
    
    // 自定义比较函数
    bool compare(const Point& a, const Point& b) {
        if (a.x != b.x) {
            return a.x < b.x;  // 按照横坐标从小到大排序
        }
        return a.y > b.y;  // 横坐标相等时,按照纵坐标从大到小排序
    }
    
    int main() {
    	freopen("point.in","r", stdin);
    	freopen("point.out","w", stdout);
        int n;
        std::cin >> n;
    
        std::vector<Point> points(n);
        for (int i = 0; i < n; ++i) {
            std::cin >> points[i].x >> points[i].y;
        }
    
        // 使用自定义比较函数进行排序
        std::sort(points.begin(), points.end(), compare);
    
        // 输出排序后的结果
        for (const auto& point : points) {
            std::cout << point.x << " " << point.y << std::endl;
        }
    
        return 0;
    }
    

    信息

    ID
    150
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    (无)
    递交数
    77
    已通过
    27
    上传者