讨论 / 我的过了,但用时多,求大神帮忙看下
yearwhk 2013-07-06 23:25:00
点我顶贴 收藏 删除
题目:排座椅

状态: Accepted

测评机: Xeost[5]

得分: 100分 [我要评价一下题目~]

提交日期: 2013-7-7 14:15:00

有效耗时: 1906毫秒

测试结果1: 通过本测试点|有效耗时219ms

测试结果2: 通过本测试点|有效耗时203ms

测试结果3: 通过本测试点|有效耗时203ms

测试结果4: 通过本测试点|有效耗时188ms

测试结果5: 通过本测试点|有效耗时187ms

测试结果6: 通过本测试点|有效耗时156ms

测试结果7: 通过本测试点|有效耗时219ms

测试结果8: 通过本测试点|有效耗时172ms

测试结果9: 通过本测试点|有效耗时171ms

测试结果10:通过本测试点|有效耗时188ms

提交代码

program seat;

var

m,n,k,l,d,x,y,p,q,t,i,j,ma,mb:longint;

a,b,a1,b1:array[1..1001] of longint;

fa,fb:array[1..1001] of boolean;

begin

fillchar(fa,sizeof(fa),false);

fillchar(fb,sizeof(fb),false);

fillchar(a,sizeof(a1),0);

fillchar(b,sizeof(b1),0);

readln(m,n,k,l,d); //读入+初始化

for i:=1 to d do begin

readln(x,y,p,q);

if (x=p) and (y<q) then inc(b[y]) else

if (x=p) and (y>q) then inc(b[q]) else

if (y=q) and (x<p) then inc(a[x]) else

inc(a[p]); //读入位置数据,数组a,b表示交头接耳的人所在位置的出现次数多少

end;

for i:=1 to m do a1[i]:=i;

for i:=1 to n do b1[i]:=i; //储存行列编号信息

for i:=m downto 2 do

for j:=1 to i-1 do

if a[j]<a[j+1] then begin

t:=a[j]; a[j]:=a[j+1]; a[j+1]:=t;

t:=a1[j]; a1[j]:=a1[j+1]; a1[j+1]:=t; end;

for i:=n downto 2 do

for j:=1 to i-1 do

if b[j]<b[j+1] then begin

t:=b[j]; b[j]:=b[j+1]; b[j+1]:=t;

t:=b1[j]; b1[j]:=b1[j+1]; b1[j+1]:=t; end; //双冒泡排序

ma:=0; mb:=0;

for i:=1 to k do begin

fa[a1[i]]:=true;

if a1[i]>ma then ma:=a1[i]; end;

for i:=1 to l do begin

fb[b1[i]]:=true;

if b1[i]>mb then mb:=b1[i]; end; //找出最大行列编号,并记录

for i:=1 to ma-1 do if fa[i] then write(i,' ');

writeln(ma);

for i:=1 to mb-1 do if fb[i] then write(i,' ');

write(mb); //输出,ma、mb的作用主要是避免输出空格

end.

查看更多回复
提交回复