Title Description
Input and output formats
Input Format
The first line, with a \ (5 \) space-separated integers are \ (M, N, K, L, D (2 \ le N, M \ le 1000,0 \ le K <M, 0 \ le L <N, D \ le 2000) \) next \ (D \) rows, each row having \ (4 \) space-separated integers. The first \ (I \) row \ (4 \) integer \ (X_i, Y_i, P_i, Q_i \) , represents a sitting position \ ((X_i, Y_i) \ ) and \ ((P_i, Q_i) \ ) the two students will whisper (before and after they enter to ensure that adjacent or horizontally adjacent). Input data to ensure the uniqueness of the optimal solution.
Output Format
Sample input and output
Input Sample # 1
4 5 1 2 3
4 2 4 3
2 3 3 3
2 5 2 4
Sample Output # 1
2
2 4
Explanation
The above figure by the symbol *, ※, + marked \ (3 \) position of the student will be whispering, FIG \ (3 \) thick line indicates the position of the channel, the channel division scheme is illustrated only the best solution.
In 2008 the popularity of Group II title
Thinking
You can direct simulation, must pay attention to the output from small to large.
Code
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 10;
int M, N, K, L, D;
set<int> ansl, ansc;
struct node
{
int id;
int val;
bool operator<(const node &rhs)
{
return val > rhs.val;
}
} lin[MAXN], cal[MAXN];
bool cmp(const node& a, const node& b)
{
return a.id < b.id;
}
void init(int m, int n)
{
for (int i = 1; i <= m; i++)
{
lin[i].id = i;
lin[i].val = 0;
}
for (int i = 1; i <= n; i++)
{
cal[i].id = i;
cal[i].val = 0;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
cin >> M >> N >> K >> L >> D;
init(M, N);
for (int i = 0; i < D; i++)
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2)
cal[min(y1, y2)].val++;
else
lin[min(x1, x2)].val++;
}
sort(lin + 1, lin + 1 + M);
sort(cal + 1, cal + 1 + N);
sort(lin + 1, lin + 1 + K, cmp);
sort(cal + 1, cal + 1 + L, cmp);
for (int i = 1; i <= K; i++)
{
if (i != 1)
cout << " ";
cout << lin[i].id;
if(i == K)cout << endl;
}
for (int i = 1; i <= L; i++)
{
if (i != 1)
cout << " ";
cout << cal[i].id;
if(i == L)cout << endl;
}
}