讨论 / 麻烦各位大虾帮我看看程序 ,错哪啦?只得40
zsx1 2009-04-18 19:06:00
点我顶贴 收藏 删除
program zzz;

var a,b:array[1..20,1..20] of integer;c,d:array[1..400] of integer;m,n,k,i,j,i1,j1,q,w,x,y:integer;

begin

readln(m,n,k);

for i:=1 to m do

for j:=1 to n do begin

read(a[i,j]); b[i,j]:=i*10+j;w:=w+1;c[w]:=a[i,j];d[w]:=b[i,j];end;

for i:=1 to m*n-1 do

for j:=i+1 to m*n do

if c[i]<c[j] then begin

q:=c[i];c[i]:=c[j];c[j]:=q; q:=d[i];d[i]:=d[j];d[j]:=q;

end;i:=1;x:=c[1];y:=(d[1] mod 10)+1; if k>=2*y-1 then begin

repeat

i:=i+1;

x:=c[i]+x;

y:=abs((d[i] div 10)-(d[i-1] div 10))+abs((d[i] mod 10)-(d[i-1] mod 10))+y+1;

until y+(d[i] mod 10)>k;

write(x-c[i]); end else write(0);

end.

#1 小小小学生@2009-04-18 19:01:00
回复 删除
我看你的有点晕

你看我的一定更晕。。。。

program li;

var n,m,k,max:longint;

a:array[0..21,0..21] of longint;

procedure init;

var i,j:longint;

begin

readln(m,n,k);

for i:=1 to m do

for j:=1 to n do

read(a[i,j]);

end;

procedure doit;

var i,j,i1,j1,t,temp:longint;

b:array[0..400,1..2] of longint;

begin

t:=0;

for i:=1 to m do

for j:=1 to n do

if a[i,j]<>0 then

begin inc(t); b[t,1]:=i; b[t,2]:=j; end;

b[t+1,1]:=0; b[t+1,2]:=0;

for i:=1 to t-1 do

for j:=1 to t-i+1 do

if a[b[j,1],b[j,2]]<a[b[j+1,1],b[j+1,2]] then

begin

temp:=b[j,1]; b[j,1]:=b[j+1,1]; b[j+1,1]:=temp;

temp:=b[j,2]; b[j,2]:=b[j+1,2]; b[j+1,2]:=temp;

end;

temp:=0; max:=0;

if k-2*b[1,1]-1>0 then

begin

k:=k-b[1,1]-1; max:=max+a[b[1,1],b[1,2]];

end else begin writeln(0); halt;end;

while (k>0) and (temp<t) do

begin

inc(temp);

i:=b[temp,1]; j:=b[temp,2];

i1:=b[temp+1,1]; j1:=b[temp+1,2];

if temp<>t then

begin

if k-(abs(i-i1)+abs(j-j1)+1)-i1>=0 then

begin k:=k-(abs(i-i1)+abs(j-j1)+1); max:=max+a[i1,j1]; end

else exit;

end;

if temp=t then

if k-i>=0 then

begin k:=k-i; end;

end;

end;

begin

init;

if k=0 then begin writeln(0); halt; end else

doit;

writeln(max);

end.

#2 zsx@2009-04-18 19:06:00
回复 删除
m,n在1-20之间,而不是1-9

所以最好用一维数组来读,并用2个一维来纪录花生的位置。排序的时候交换就行啦。

查看更多回复
提交回复