讨论 / AC pascal 原代码
潘崇明 2016-02-12 16:15:42
点我顶贴 收藏 删除
program peanuts;

var

m,n,k:integer;

t,j,j2,i2,i:integer;

j1,i1,l:integer;

a:array[1..100,1..100]of integer;

b:boolean;

begin

read(input,m,n,k);

dec(k);

for j:=1 to m do

for i:=1 to n do

read(input,a[j,i]);

b:=true;

j1:=1;

i1:=1;

for j:=1 to m do

for i:=1 to n do

if a[j1,i1]<a[j,i] then begin j1:=j;i1:=i; end;

j1:=1;j2:=1;i2:=1;

while b do

begin

for j:=1 to m do

for i:=1 to n do

if a[j2,i2]<a[j,i] then begin j2:=j; i2:=i; end;

t:=abs(j1-j2)+abs(i1-i2)+abs(j2-0)+1;

if k>=t then begin

l:=l+a[j2,i2];

k:=k-t+abs(j2-0);

a[j2,i2]:=0;

j1:=j2;

i1:=i2;

j2:=1;

i2:=1;

end

else break;

b:=false;

for j:=1 to m do

for i:=1 to n do

if a[j,i]>0 then begin b:=true; break; break;end;

end;

write(output,l);

end.

查看更多回复
提交回复