简单的模拟——排座椅
来源:互联网 发布:淘宝投诉人工服务电话 编辑:程序博客网 时间:2024/04/28 16:58
SSL 1592
洛谷 P1056 排座椅
题目描述
上课的时候总会有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情。不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的D对同学上课时会交头接耳。同学们在教室中坐成了M行N列,坐在第i行第j列的同学的位置是(i,j),为了方便同学们进出,在教室中设置了K条横向的通道,L条纵向的通道。于是,聪明的小雪想到了一个办法,或许可以减少上课时学生交头接耳的问题:她打算重新摆放桌椅,改变同学们桌椅间通道的位置,因为如果一条通道隔开了两个会交头接耳的同学,那么他们就不会交头接耳了。
请你帮忙给小雪编写一个程序,给出最好的通道划分方案。在该方案下,上课时交头接耳的学生的对数最少。
分析或思路
读入1对学生坐标时,为该行或该列的数组+1(即该行或列可以分割多少名学生)然后分别排序这些数值,最后从大到小累加,直到该行或该列不能分割为止
(这里给个提醒:用选择排序或冒泡排序,使用快排会有神秘的错误!)
type arr=array[1..1000]of longint;var h,k1,k2,l,n,x1,x2,y1,y2,i,j:longint; a1,a2,x,b,a:arr;procedure qsort(k:longint);var i,j,t:longint;begin for i:=1 to k-1 do for j:=i+1 to k do if b[i]>b[j] then begin t:=b[i]; b[i]:=b[j]; b[j]:=t; end;end;procedure sort(n:longint);var i,j,t:longint;begin for i:=1 to n-1 do for j:=i+1 to n do if (a[i]<a[j]) then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; t:=b[i]; b[i]:=b[j]; b[j]:=t; end;end;begin read(h,l,k1,k2,n); for i:=1 to n do begin readln(x1,y1,x2,y2); if x1=x2 then begin if y1>y2 then inc(a1[y2]); if y1<y2 then inc(a1[y1]); end; if y1=y2 then begin if x1>x2 then inc(a2[x2]); if x1<x2 then inc(a2[x1]); end; end; for i:=1 to l do x[i]:=i; a:=a2; b:=x; sort(l); qsort(k1); for i:=1 to k1 do write(b[i],' '); for i:=1 to h do x[i]:=i; writeln; a:=a1; b:=x; sort(h); qsort(k2); for i:=1 to k2 do write(b[i],' ');end.
0 0
- 简单的模拟——排座椅
- 洛谷 1056——排座椅(简单的模拟)
- 普及练习场 简单的模拟 排座椅
- 排座椅
- 排座椅
- 排座椅
- 排座椅
- 排座椅
- 【NOIP普及组】2016模拟考试(10.29)——排座椅
- 排座椅 题解
- 【贪心】排座椅
- sicily1762 排座椅
- 排座椅【贪心】
- P1007 --- 排座椅
- TYVJ P1007 排座椅
- TYVJ P1007 排座椅
- 洛谷1056 排座椅
- NOIP 2008 - 排座椅
- H3 BPM 跨平台表单发起详解
- Net设计模式实例之备忘录模式(Memento Pattern)
- [FireDAC][Phys][ODBC][Mirosoft][ODBC SQL Server Driver]COUNT 字段不正确或语法错误
- eclipse:Project is already imported into workspace
- HTML5调用手机摄像机、相册功能 <input>方法
- 简单的模拟——排座椅
- cude之helloworld
- Cookie 记住密码
- 31、Power Query-行、列、表的构造
- Verilog wire和reg分析1
- Spring AOP 实现原理
- 1-javascript基本类型总结
- iOS 单例模式
- retrofit上传图片