我的贪心思想是这样的:优先挑能隔开人最多的行/列,并用结构体中的val来保存,最后排序按照顺序输出,而且我也比较了号码大小。。。但不知道为什么0分。下载的第一个数据点是这样的:
3 3 1 1 2
1 1 1 2
1 1 2 1
答案应该是1 1,而我本地测试输出的也是1 1 QwQ
代码如下:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for(int i = m; i <= n; i++)
#define per(i, m, n) for(int i = m; i >= n; i--)
#define ll long long
#define pb push_back
struct r {
int val, id;
}row[1005];
struct c {
int val, id;
}col[1005];
bool cmp(r a, r b) {
if (a.val == b.val) return a.id < b.id;
return a.val > b.val;
}
bool cmp2(c a, c b) {
if (a.val == b.val) return a.id < b.id;
return a.val > b.val;
}
int main() {
ios::sync_with_stdio(false);
int m, n, p, q, k;
cin >> m >> n >> p >> q >> k;
rep(i, 1, m) row[i].id = i;
rep(i, 1, n) col[i].id = i;
while (k--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a == c) {
col[min(b, d)].val ++;
}
else if (b == d) {
row[min(a, c)].val ++;
}
}
sort(col + 1, col + n + 1, cmp2);
sort(row + 1, row + m + 1, cmp);
rep(i, 1, p) {
cout << row[i].id << " ";
}
cout << endl;
rep(i, 1, q) {
cout << col[i].id << " ";
}
cout << endl;
return 0;
}