前言
胖嘟嘟的刘嘟嘟老师来了!今天
题目描述
上课的时候总有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情。不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的D对同学上课时会交头接耳。同学们在教室中坐成了M行N列,坐在第i行第j列的同学的位置是(i,j),为了方便同学们进出,在教室中设置了K条横向的通道,L条纵向的通道。于是,聪明的小雪想到了一个办法,或许可以减少上课时学生交头接耳的问题:她打算重新摆放桌椅,改变同学们桌椅间通道的位置,因为如果一条通道隔开了两个会交头接耳的同学,那么他们就不会交头接耳了。
请你帮忙给小雪编写一个程序,给出最好的通道划分方案。在该方案下,上课时交头接耳的学生对数最少。
输入
输出
输出文件seat.out共两行。
第一行包含K个整数,a1a2……aK,表示第a1行和a1+1行之间、第a2行和第a2+1行之间、…、第aK行和第aK+1行之间要开辟通道,其中ai< ai+1,每两个整数之间用空格隔开(行尾没有空格)。
第二行包含L个整数,b1b2……bk,表示第b1列和b1+1列之间、第b2列和第b2+1列之间、…、第bL列和第bL+1列之间要开辟通道,其中bi< bi+1,每两个整数之间用空格隔开(行尾没有空格)。
样例输入
4 5 1 2 3
4 2 4 3
2 3 3 3
2 5 2 4
样例输出
2
2 4
样例解释
思路
很搞事情的一道题。暴力模拟搞事情,拿刀直接干。哪行那列有讲话的,直接把他俩暴力分开就行了。h数组=hang行,记录行,l=lie列,记录列。
代码
var
a,b,h,l:array[1..2000] of longint;
i,j,k,n,m,d,o,p,xi,yi,pi,qi,dd,gg,max:longint;
begin
assign(input,'seat.in');reset(input);
assign(output,'seat.out');rewrite(output);
readln(m,n,k,o,d);
for i:=1 to d do
begin
readln(xi,yi,pi,qi);
if (yi>qi) then
begin
p:=yi;
yi:=qi;
qi:=p;
end;
if (xi>pi) then
begin
p:=xi;
xi:=pi;
pi:=p;
end;
if (xi=pi) then
begin
for j:=1 to n do
if (j=yi) then inc(l[yi]);
end
else
begin
for j:=1 to m do
if (j=xi) then inc(h[xi]);
end;
end;
j:=0;
repeat
inc(j);
max:=0;
for i:=1 to n do
begin
if (l[i]>max) then
begin
dd:=i;
max:=l[i];
end;
end;
l[dd]:=0;
a[dd]:=1;
until (o=j);
j:=0;
repeat
inc(j);
max:=0;
for i:=1 to n do
begin
if (h[i]>max) then
begin
gg:=i;
max:=h[i];
end;
end;
h[gg]:=0;
b[gg]:=1;
until (k=j);
for i:=1 to n do
if (b[i]=1) then write(i,' ');
writeln;
for i:=1 to m do
if (a[i]=1) then write(i,' ');
writeln;
close(input);
close(output);
end.