| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
不知wa哪里const way:array [1..4,1..2] of integer=((1,0),(-1,0),(0,1),(0,-1));
type data=array [1..3] of integer;
var
n,m,top:integer;
f:array [1..10000] of data;
c:array [1..100,1..100] of integer;
used:array [1..100,1..100] of boolean;
procedure run(h,t:integer);
var
q,w:integer;p:data;
begin
if h>=t then exit;
q:=h;w:=t;
p:=f[q];
while q<>w do
begin
while (q<>w) and (p[3]>=f[w,3]) do w:=w-1;
f[q]:=f[w];
while (q<>w) and (f[q,3]>=p[3]) do q:=q+1;
f[w]:=f[q];
end;
f[q]:=p;
run(h,q-1);run(q+1,t);
end;
procedure main;
var
i,j,best,x,y:integer;
begin
readln(n,m);top:=n*m;
for i:=1 to n do
begin
for j:=1 to m do
begin
top:=(i-1)*m+j;
read(f[top,3]);
f[top,1]:=i;f[top,2]:=j;
end;
readln;
end;
run(1,n*m);
fillchar(c,sizeof(c),0);
fillchar(used,sizeof(used),true);
best:=0;
for i:=1 to n*m do
begin
used[f[i,1],f[i,2]]:=false;
for j:=1 to 4 do
begin
x:=f[i,1]+way[j,1];y:=f[i,2]+way[j,2];
if (0<x) and (x<n+1) and (0<y) and (y<m+1) and (c[x,y]<c[f[i,1],f[i,2]]+1)and (used[x,y])then
begin
c[x,y]:=c[f[i,1],f[i,2]]+1;
if best<c[f[i,1],f[i,2]]+1 then best:=c[f[i,1],f[i,2]]+1;
end;
end;
end;
writeln(best+1);
end;
begin
main;
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator