题解 | 排座椅

排座椅

https://www.nowcoder.com/practice/b8dc67c35bdb47e489da682e908379f7

#include<bits/stdc++.h>
using namespace std;
int main() {
    int n, m, k, l, d;
    cin >> n >> m >> k >> l >> d;
    vector<int> row_gap(n, 0);
    vector<int> col_gap(m, 0);
    while (d--) 
    {
        int  x, y, p, q;
        cin >> x >> y >> p >> q;
        if (x != p) 
        {
            int gap = min(x, p);
            row_gap[gap]++;
        }
        if (y != q) 
        {
            int gap = min(y, q);
            col_gap[gap]++;
        }
    }
    map<int, int>arr;
    map<int, int>brr;
    for (int i = 1; i <= n - 1; i++) 
    {
        arr.insert(make_pair(i, row_gap[i]));
    }
    for (int j = 1; j <= m - 1; j++) 
    {
        brr.insert(make_pair(j, col_gap[j]));
    }
    vector<pair<int, int>> row_vec(arr.begin(), arr.end());
    sort(row_vec.begin(), row_vec.end(), [](const pair<int, int>& a,const pair<int, int>& b) 
    {
        if (a.second != b.second) return a.second > b.second;
        return a.first < b.first;
    });
    vector<int> row_res;
    for (int i = 0; i < k; i++) row_res.push_back(row_vec[i].first);
    sort(row_res.begin(), row_res.end());
    for (int i = 0; i < row_res.size(); i++)
    {
        if (i > 0) cout << " ";
        cout << row_res[i];
    }
    cout << endl;

    vector<pair<int, int>> col_vec(brr.begin(), brr.end());
    sort(col_vec.begin(), col_vec.end(), [](const pair<int, int>& a,
    const pair<int, int>& b) 
    {
        if (a.second != b.second) return a.second > b.second;
        return a.first < b.first;
    });
    vector<int> col_res;
    for (int i = 0; i < l; i++) col_res.push_back(col_vec[i].first);
    sort(col_res.begin(), col_res.end());
    for (int i = 0; i < col_res.size(); i++) {
        if (i > 0) cout << " ";
        cout << col_res[i];
    }
    cout << endl;

    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务