Topic-----------------------------------------------------------------------------------------
Portal: http://www.luogu.org/problem/show?pid=1056
P1056 Row Seat 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 example # #:
4 5 1 2 34 2 4 32 3 3 32 5 2 4
Sample # # of output:
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 2008 Noip popularization Group
Problem solving-----------------------------------------------------------------------------------------
In fact, this topic a bit of pit, debugging the majority of days, only to find that the original is not let me stop speech phenomenon, just let me to the lowest. "Life is no love
This problem is a simple simulation plus greed, first to each of the students to talk to open a channel, recorded in hang or lie, repeat the number of repetitions, and then find out the top K bar of the most cross-section of the students and the front of the longitudinal channel to separate the most vertical channels output can be
Fast line too long, too lazy to play, so it is used to bubble, of course, or over the Qaq
Code-----------------------------------------------------------------------------------------
1 ProgramPaizhuoyi;2 var3A,hang,lie:Array[0.. +] ofinteger;4 X1,y1,x2,y2,m,n,k,l,d,i,long:longint;5 proceduresort (s,e:longint);6 var7 X,y,temp:longint;8 begin9 forx:= s toE-1 DoTen fory:=x+1 toE Do One ifA[x]<a[y] Then begin Atemp:=A[x]; -a[x]:=A[y]; -a[y]:=temp; the End; - End; - begin - readln (m,n,k,l,d); + fori:=1 toD Do - begin + read (x1,y1,x2,y2); A ifX1=x2 Then begin at ifY1>y2 Theny1:=Y2; - Inc (Lie[y1]); - End - Else begin - ifX1>x2 Thenx1:=x2; - Inc (HANG[X1]); in End; - End; tolong:=0; + fori:=1 toM Do - ifHang[i]>0 Then begin the Inc (long); *a[long]:=Hang[i]; $ End;Panax NotoginsengSort1, long); - fori:=1 toM Do the ifHANG[I]>=A[K] ThenWrite (I,' '); +writeln;//--------------------------------------- Along:=0; the fori:=1 toN Do + ifLie[i]>0 Then begin - Inc (long); $a[long]:=Lie[i]; $ End; -Sort1, long); - fori:=1 toM Do the ifLIE[I]>=A[L] ThenWrite (I,' '); - End.
P1056 row seat "Luo gu"