主题:花生采摘
var b : array[0..400,1..3]of integer;
len, m, n, k, i, j, temp : integer;
max : longint;
procedure init;
var a:integer;
begin
fillchar(b,sizeof(b),0);
readln(m,n,k);
len:=0;
for i:=1 to m do
for j:=1 to n do
begin
read(a);
if a>0 then
begin
inc(len);
b[len,1]:=i; b[len,2]:=j; b[len,3]:=a;
end;
end;
end;
procedure sort;
var flag:boolean;
begin
flag:=true;
for i:=1 to len-1 do
begin
for j:=1 to len-i do
if b[j,3]<b[j+1,3] then
begin
b[0]:=b[j+1]; b[j+1]:=b[j]; b[j]:=b[0];
flag:=false;
end;
if flag then exit;
end;
end;
function dis(i,t:integer):boolean;
begin
temp:=0;
for j:=1 to 2 do
begin
temp:=temp+abs(b[i,j]-b[i-1,j]);
end;
if temp+b[i,1]<t then begin dis:=true; exit; end
else dis:=false;
end;
procedure work;
begin
i:=1; max:=0;
while (dis(i,k)) and (i<=len) do
begin
k:=k-temp;
max:=max+b[i,3];
inc(i);
end;
end;
procedure print;
begin
writeln(max);
end;
begin{main}
init;
sort;
work;
print;
end.
题目是vijos上的1120(www.vijos.cn)题目名字是花生采摘,竞赛题,求助为什么错了。[em10][em10][em10]
len, m, n, k, i, j, temp : integer;
max : longint;
procedure init;
var a:integer;
begin
fillchar(b,sizeof(b),0);
readln(m,n,k);
len:=0;
for i:=1 to m do
for j:=1 to n do
begin
read(a);
if a>0 then
begin
inc(len);
b[len,1]:=i; b[len,2]:=j; b[len,3]:=a;
end;
end;
end;
procedure sort;
var flag:boolean;
begin
flag:=true;
for i:=1 to len-1 do
begin
for j:=1 to len-i do
if b[j,3]<b[j+1,3] then
begin
b[0]:=b[j+1]; b[j+1]:=b[j]; b[j]:=b[0];
flag:=false;
end;
if flag then exit;
end;
end;
function dis(i,t:integer):boolean;
begin
temp:=0;
for j:=1 to 2 do
begin
temp:=temp+abs(b[i,j]-b[i-1,j]);
end;
if temp+b[i,1]<t then begin dis:=true; exit; end
else dis:=false;
end;
procedure work;
begin
i:=1; max:=0;
while (dis(i,k)) and (i<=len) do
begin
k:=k-temp;
max:=max+b[i,3];
inc(i);
end;
end;
procedure print;
begin
writeln(max);
end;
begin{main}
init;
sort;
work;
print;
end.
题目是vijos上的1120(www.vijos.cn)题目名字是花生采摘,竞赛题,求助为什么错了。[em10][em10][em10]