这题其实只要想清楚就不难的了。就是按什么规则来选择哪两行或者哪两列直接是否该间隔。
我的规则就是记录每两行或者两列有交谈的对数。当然按题意,会把这个记录在行号或者列号较小的地方。
//===================
#include <iostream>
#include <algorithm>
using namespace std;
struct pos {
pos(){
num = 0;
}
int p;
int num;
};
int great(pos a, pos b)
{
return a.num > b.num;
}
int little(pos a, pos b) {
return a.p < b.p;
}
int main()
{
int m, n, k, l, d;
while (cin >> m) {
cin >> n >> k >> l >> d;
int i;
pos xx[2010], yy[2010];
int x1, y1, x2, y2;
for (i = 1; i <= m; i++)
xx[i].p = i;
for (i = 1; i <= n; i++)
yy[i].p = i;
for (i = 0; i < d; i++) {
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2)
{
y1 = y1 < y2 ? y1 : y2;
yy[y1].num++;
}
else {
x1 = x1 < x2 ? x1 : x2;
xx[x1].num++;
}
}
sort(xx, xx+m, great);
sort(yy, yy+n, great);
if (k != 0) {
//在这里犯傻了,没看到题目说要升序输出,所以告诫后来人!!!!!
sort(xx, xx+k, little);
for (i = 0; i < k-1; i++)
cout << xx[i].p << ' ';
cout << xx[i].p << endl;
}
if (l != 0) {
sort(yy, yy+l, little);
for (i = 0; i < l-1; i++)
cout << yy[i].p << ' ';
cout << yy[i].p << endl;
}
}
return 0;
}