排座椅
来源:互联网 发布:ubuntu网易云音乐乱码 编辑:程序博客网 时间:2024/04/24 15:22
题目:
题目描述
上课的时候总会有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情。不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的D对同学上课时会交头接耳。同学们在教室中坐成了M行N列,坐在第i行第j列的同学的位置是(i,j),为了方便同学们进出,在教室中设置了K条横向的通道,L条纵向的通道。于是,聪明的小雪想到了一个办法,或许可以减少上课时学生交头接耳的问题:她打算重新摆放桌椅,改变同学们桌椅间通道的位置,因为如果一条通道隔开了两个会交头接耳的同学,那么他们就不会交头接耳了。
请你帮忙给小雪编写一个程序,给出最好的通道划分方案。在该方案下,上课时交头接耳的学生的对数最少。
输入输出格式
输入格式:
输入文件seat.in的第一行,有5个用空格隔开的整数,分别是M,N,K,L,D(2<=N,M<=1000,0<=K
const maxn=1001;type arr=array[0..maxn,1..2]of integer;var a,b:arr; i,t,m,n,k,l,d:longint;procedure qsort1(l,r,t:longint);var key,i,j:longint;begin if l>=r then exit; i:=l; j:=r; key:=b[(l+r) div 2,t]; repeat while b[i,t]>key do inc(i); while b[j,t]<key do dec(j); if i<=j then begin b[0]:=b[i];b[i]:=b[j];b[j]:=b[0]; inc(i);dec(j); end; until i>j; qsort1(l,j,t); qsort1(i,r,t);end;procedure qsort(l,r,t:longint);var key,i,j:longint;begin if l>=r then exit; i:=l; j:=r; key:=a[(l+r) div 2,t]; repeat while a[i,t]>key do inc(i); while a[j,t]<key do dec(j); if i<=j then begin a[0]:=a[i];a[i]:=a[j];a[j]:=a[0]; inc(i);dec(j); end; until i>j; qsort(l,j,t); qsort(i,r,t);end;procedure init;var i,j,x,y,x1,y1:longint;begin readln(m,n,k,l,d); for i:=1 to d do begin readln(x,y,x1,y1); if (x=x1) then if y>y1 then begin inc(b[y1,1]); b[y1,2]:=y1; end else if y<y1 then begin inc(b[y,1]); b[y,2]:=y; end; if (y=y1) then if x>x1 then begin inc(a[x1,1]); a[x1,2]:=x1; end else if x<x1 then begin inc(a[x,1]); a[x,2]:=x; end; end; qsort(1,n,1); qsort1(1,m,1);end;begin init; qsort(1,k,2); qsort1(1,l,2); for i:=k downto 1 do if i<>1 then write(a[i,2],' ') else write(a[i,2]); writeln; for i:=l downto 1 do if i<>1 then write(b[i,2],' ') else write(b[i,2]); writeln;end.
1 0
- 排座椅
- 排座椅
- 排座椅
- 排座椅
- 排座椅
- 排座椅 题解
- 【贪心】排座椅
- sicily1762 排座椅
- 排座椅【贪心】
- P1007 --- 排座椅
- TYVJ P1007 排座椅
- TYVJ P1007 排座椅
- 洛谷1056 排座椅
- NOIP 2008 - 排座椅
- NOIP2008(2)排座椅
- P1007排座椅
- 【sort】 排座椅
- 排座椅【贪心】
- 【C语言】折半查找
- Java反编译工具
- 向web网页填写内容 自动登录
- WebOffice插件js方法
- 【JZOJ4935】【NOIP2017GDKOI模拟1.12】b
- 排座椅
- 通过UIKit坐标系来全面掌握iOS中的UIScrollView组件
- 算法训练 幂方分解
- 基于感知损失函数的实时风格转换和超分辨率重建
- 拉格朗日插值
- 用MongoTemplate查询指定字段的正确奥义
- 进制转换 pascal.
- SSM框架整合小结(下) spring+Mybatis
- iOS开发UIScrollView的底层实现-你也可以自己实现一个scrollView