看似复杂,其实挺简单
最后注意,ans是按从小到大输出的
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1e5 + 5;
int ansx[maxn], ansy[maxn];
struct node {
int num;
int pos;
}x[maxn], y[maxn];
bool cmp(node A, node B) {
return A.num > B.num;
}
int main() {
int m, n, k, l, d;
cin >> m >> n >> k >> l >> d;
while (d--) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2) {
int temp = min(y1, y2);
y[temp].pos = temp;
y[temp].num++;
}
if (y1 == y2) {
int temp = min(x1, x2);
x[temp].pos = temp;
x[temp].num++;
}
}
sort(x + 1, x + m + 1, cmp);
sort(y + 1, y + n + 1, cmp);
for (int i = 1;i <= k;i++)
ansx[i] = x[i].pos;
for (int i = 0;i <= l;i++)
ansy[i] = y[i].pos;
sort(ansx + 1, ansx + 1 + k);
sort(ansy + 1, ansy + 1 + l);
for (int i = 1;i <= k;i++)
cout << ansx[i] << ' ';
cout << endl;
for (int i = 1;i <= l;i++)
cout << ansy[i] << ' ';
cout << endl;
return 0;
}