Rokua P1056 row seat "greedy/structured sort"

Source: Internet
Author: User

Title Description

In class, there will always be some students and around the people whispering, this is to make the primary school teacher is very headache one 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/output format

Input format:

The first line of the input file seat.in, with 5 integers separated by spaces, is m,n,k,l,d (2<=n,m<=1000,0<=k<m,0<=l<n,d<=2000).

The next D line, each line has 4 integers separated by a space. The 4 integer xi,yi,pi,qi of line I, which indicates 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 format:

Output file Seat.out A total of two lines.

The first line contains k integers, A1,a2......ak, which indicate that between the A1 line and the A1+1 line, between the A2 row and the A2+1 line 、...、 between the AK line and the ak+1 line, where ai< ai+1, separated by a space between each of the two integers (no spaces at the end of the line).

The second line contains an L integer, B1,B2......BL, which indicates that between the B1 column and the B1+1 column, between the B2 column and the b2+1 column 、...、 to channel between the BL and bl+1 columns, where bi< bi+1, separated by a space between each of the two integers (no spaces at the end of the column).

Input and Output sample input sample #: Copy
4 5 1 2 34 2 4 32 3 3 32 5 2 4
Output Example # #: Replication
22 4
Description

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.

The second problem of the 2008 popularization group

"Code":

/*Simplified test instructions: The same row of the left and right two columns of speech, the same column of the top and bottom two rows of speech, to find out each row of the number of speakers to sort rows (columns) to make a series of divisions, so that the sum of the separated groups most attention: Label sorting! Label Sort! Label Sort! Important Words three times the speaker every two people a group of points: the ranks of the discussion, and should take the smaller subscript sum of the largest, so think first count reorder, while note that the subscript output should be ascending*/#include<bits/stdc++.h>#include<cstdio>#include<algorithm>#include<cmath>using namespacestd;structpoint{intX,n;//x indicates the row or column where the line is to be detached n means that the line can separate the number of speakers}y[1001],x[1001];//x is row y is the columnBOOLCMP1 (Point A,point b) {returna.n>b.n;//sorting will be separated by a large amount of put in front to ensure optimal}BOOLCMP2 (Point A,point b) {returna.x<b.x;//ask for the number of columns (number of rows) in front of the}intMain () {intm,n,k,l,d; scanf ("%d %d%d%d%d",&m,&n,&k,&l,&d); intx1,y1,p1,q1;  for(intI=1; i<=d;i++) {scanf ("%d %d%d%d",&x1,&y1,&p1,&Q1); if(X1==P1) {//The distinction is longitudinal or transverse, if the horizontal is the same, the separation line is longitudinalY[min (Y1,Q1)].x=min (Y1,Q1);//mark the number of columns in a split lineY[min (Y1,Q1)].n++;//y[min (Y1,Q1)].x guarantees the same number of columns split line overlay        }        if(Y1==Q1) {//similarlyX[min (X1,P1)].x=min (X1,P1); X[min (X1,P1)].N++; }} sort (x+1, x+1+M,CMP1);//large number of separations in frontSort (y+1, y+1+N,CMP1);//here is the greedy, find the most able to separate the number of roads, then the speaker is lessSort (x+1, x+1+K,CMP2);//Organize answers (the number of rows or columns is small)Sort (y+1, y+1+L,CMP2);  for(intI=1; i<=k;i++) printf ("%d", x[i].x); printf ("\ n");//output Middle line break     for(intI=1; i<=l;i++) printf ("%d", y[i].x); return 0;}

Rokua P1056 row seat "greedy/structured sort"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.