题解
2026-10-31 18:12:07
发布于:浙江
6阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
struct Line {
int id; // 通道位置(行/列编号)
int cnt; // 该位置能隔开几对同学
};
int main() {
int M, N, K, L, D;
cin >> M >> N >> K >> L >> D;
vector<Line> row(M), col(N); // row: 横向通道,col: 纵向通道
for (int i = 0; i < M; i++) row[i].id = i;
for (int i = 0; i < N; i++) col[i].id = i;
int x, y, p, q;
for (int i = 0; i < D; i++) {
cin >> x >> y >> p >> q;
if (x == p) { // 左右相邻 -> 纵向通道(col)
col[min(y, q)].cnt++;
} else { // 上下相邻 -> 横向通道(row)
row[min(x, p)].cnt++;
}
}
// 按 cnt 降序,取前 K 条横向、前 L 条纵向
sort(row.begin(), row.end(), [](Line a, Line b) { return a.cnt > b.cnt; });
sort(col.begin(), col.end(), [](Line a, Line b) { return a.cnt > b.cnt; });
vector<int> ansRow, ansCol;
for (int i = 0; i < K; i++) ansRow.push_back(row[i].id);
for (int i = 0; i < L; i++) ansCol.push_back(col[i].id);
// 输出需要从小到大
sort(ansRow.begin(), ansRow.end());
sort(ansCol.begin(), ansCol.end());
for (int i = 0; i < K; i++) {
if (i) cout << " ";
cout << ansRow[i];
}
cout << "\n";
for (int i = 0; i < L; i++) {
if (i) cout << " ";
cout << ansCol[i];
}
cout << "\n";
return 0;
}
全部评论 1
求赞,求关注(必回哦~)

7小时前 来自 浙江
1

有帮助,赞一个