题目描述
教室有M行N列,坐在第i行第j列的同学的位置是(i,j),为了方便同学们进出,在教室中设置了K条横向的通道,L条纵向的通道。如果一条通道隔开了两个会交头接耳的同学,那么他们就不会交头接耳了。样例输入
4 5 1 2 34 2 4 32 3 3 32 5 2 4样例输出
22 4思路
O(2nm^2)把每行每列的同学对数记录下来,贪心。var x,y,s:array[1..2000] of longint; a:array[1..2000,1..4] of longint; m,n,k,l,d,i,j,t:longint;function min(x,y:longint):longint;begin if x<y then min:=x else min:=y;end;begin readln(m,n,k,l,d); for i:= 1 to d do begin read(a[i,1],a[i,2],a[i,3],a[i,4]); if a[i,1]=a[i,3] then inc(x[min(a[i,2],a[i,4])]) else inc(y[min(a[i,1],a[i,3])]); end; for i:= 1 to m do if y[i]>0 then begin inc(j); s[j]:=y[i]; end; for i:=1 to j-1 do for j:=i+1 to j do if s[i]<s[j] then begin t:=s[i];s[i]:=s[j];s[j]:=t;end; for i:=1 to m do if y[i]>=s[k] then write(i,' '); writeln; j:=0; fillchar(s,sizeof(s),0); for i:= 1 to n do if x[i]>0 then begin inc(j); s[j]:=x[i]; end; for i:=1 to j-1 do for j:=i+1 to j do if s[i]<s[j] then begin t:=s[i];s[i]:=s[j];s[j]:=t;end; for i:=1 to m do if x[i]>=s[l] then write(i,' ');end.