Row seats (seat) Title Description
In class, there are always some students and around the people whispering, this is to make the primary school teacher is a very headache thing. However, the teacher in charge of snow found some interesting phenomenon, when the students to determine the seating, only a limited D to the students will whisper in class. The students sit in the classroom in the M row N column, sitting in the first row of the classmate in column J is (I,J), in order to facilitate the students in and out, in the classroom set K horizontal channel, L longitudinal channel. So, the clever light snow thought of a method, perhaps can reduce the students in the class to whisper the question: she intends to rearrange the table and chairs, change the position of the students and chairs between the aisle, because if a channel separated by two will whisper students, then they will not whisper.
Please help the snow to write a program, give the best channel partitioning scheme. Under this scheme, the number of students whispering in class is the least.
Input
In the first line, there are 5 integers separated by spaces, respectively, M,n,k,l,d (2<=n,m<=1000,0<=k<m,0<=l<n,d<=2000).
Next to the D line, each line has 4 integers separated by spaces, and the 4 integers of line I are Xi,yi,pi,qi, indicating that the seated position (xi,yi) is whispering to the two alumni (PI,QI) (the input guarantees that they are adjacent to each other or left and right). The input data guarantees the uniqueness of the optimal scheme.
Output
A total of two lines.
The first line contains k integers, A1a2......ak, representing the line between the A1 and A1+1 lines, the A2 line and the A2+1 line between the 、...、 AK line and the ak+1 line to channel, where ai< ai+1, each two integers separated by a space (no space at the end of the line).
The second line contains l integers, B1B2......BK, between the B1 column and the B1+1 column, between the B2 column and the b2+1 column 、...、 between the BL column and the Bl+1 column, where bi< bi+1, separated by a space between each of the two integers (no spaces at the end of the line).
Sample input
4 5 1 2 34 2 4 32 3 3 32 5 2 4
Sample output
22 4
Tips
With the symbol *, ※, + marked 3 pairs of students will be whispering position, the figure of 3 lines of the position of the channel, the diagram of the channel partition scheme is the only best solution.
Analysis: Statistics may be the answer row and column occurrences of the maximum number of K and L, respectively, pay attention to the output answer is ordered.
Code:
#include <bits/stdc++.h>#defineFi first#defineSe Secondusing namespacestd;Const intmaxn=1e3+Ten;intN,m,l,d;pair<int,int>A[MAXN],B[MAXN];intMain () {inti,j,k,t; scanf ("%d%d%d%d%d",&m,&n,&k,&l,&d); for(intI=0; i<d;i++) { intf[4]; for(intj=0;j<4; j + +) scanf ("%d",&F[j]); if(f[1]==f[3]) A[min (f[0],f[2])].first++,a[min (f[0],f[2])].se=min (f[0],f[2]); ElseB[min (f[1],f[3])].first++,b[min (f[1],f[3])].se=min (f[1],f[3]); } sort (A,a+MAXN); Sort (b,b+MAXN); Set<int>p,q; for(inti=maxn-1;; i--) {P.insert (a[i].se);if(P.size () ==k) Break; } for(inti=maxn-1;; i--) {Q.insert (b[i].se);if(Q.size () ==l) Break; } J=0; for(intX:P) {if(j) printf ("%d", x);Elseprintf"%d", x), j=1;} printf"\ n"); J=0; for(intX:Q) {if(j) printf ("%d", x);Elseprintf"%d", x), j=1;} printf"\ n"); //System ("pause"); return 0;}
Row seats (seat)