Row seat time limit: 1 Sec memory limit: MB
Submissions: 4 Resolution: 3
Submitted State [Discussion Version] [Propositional person: external import] 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 students in column J position 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.
Enter the first row of each set of input data, with 5 integers separated by spaces, 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 or left and right).
The input data guarantees the uniqueness of the optimal scheme.
Output
Each set of outputs is a total of two rows.
The first line contains K integers, A1 A2...ak, which indicate between the A1 line and the A1+1 line, between the A2 line and the A2+1 row, between the 、...、 AK line and the ak+1 line, where ai<ai+1, each two integers separated by a space (no spaces at the end of the line).
The second line contains l integers, B1 b2...bk, which indicate 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 to channel, where bi<bi+1, each two integers separated by a space (no space at the end of the line).
The following is an explanation of the sample data:
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.
Sample input
4 5 1 2 34 2 4 32 3 3 32 5 2 4
Sample output
22 4
Tips
#include <iostream>#include<algorithm>#include<vector>using namespacestd;structedge{intnum; intsum;}; BOOLCmp1 (Edge A,edge b) {returnA.sum >B.sum;} BOOLCMP2 (Edge A,edge b) {returnA.num <B.num;} Edge row[2001];edge col[2001]; intMain () {intm,n,k,l,d; while(Cin >>M) {cin>> N >> K >> L >>D; inti; for(i =0; I < m;i++) {Row[i].num= i +1; Row[i].sum=0; } for(i =0; I < n;i++) {Col[i].num= i +1; Col[i].sum=0; } for(i =0; I < d;i++) { intA,b,x,y; CIN>> a >> b >> x >>y; if(A = =x) {col[min (b,y)-1].sum++;; } if(b = =y) {row[min (a,x)-1].sum++; } } //Trap One: Note that the numbers are to be output in ascending order.Sort (row,row+M,CMP1); Sort (Col,col+N,CMP1); Sort (Row,row+K,CMP2); Sort (Col,col+L,CMP2); //Note: You do not have to output a space after the last item for(i =0; I < k;i++) { if(I! = K-1) cout<< Row[i].num <<' '; Elsecout<<Row[i].num; } cout<<Endl; for(i =0; I < l;i++) { if(I! = L-1) cout<< Col[i].num <<' '; Elsecout<<Col[i].num; } cout<<Endl; } return 0;}
Universal group 2008NOIP Row seats (greedy + sort)