Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:我的也超时,哪位牛帮忙看看。

Posted by cage at 2008-07-08 20:08:52 on Problem 1088
In Reply To:我的也超时,哪位牛帮忙看看。 Posted by:ForFly at 2008-04-16 20:34:28
> program pku_1088;
> var
>   r,c,i,j,t,ans,tot:integer;
>   a,f:array[1..100,1..100]of integer;
>   v:array[1..100,1..100]of boolean;
> function max(x,y:integer):integer;
> begin
>   if x>y then max:=x
>   else max:=y;
> end;
> function init(x,y:integer):boolean;
> begin
>   if (1<=x) and (r>=x) and (1<=y) and (c>=y) then init:=true else init:=false;
> end;
> function d(x,y:integer):boolean;
> var
>   vv:boolean;
> begin
>   vv:=true;;
>   if init(x+1,y) then if a[x+1,y]<a[x,y] then vv:=false;
>   if init(x-1,y) then if a[x-1,y]<a[x,y] then vv:=false;
>   if init(x,y+1) then if a[x,y+1]<a[x,y] then vv:=false;
>   if init(x,y-1) then if a[x,y-1]<a[x,y] then vv:=false;
>   d:=vv;
> end;
> 
> function ok(x,y:integer):boolean;
> var
>   vv:boolean;
> begin
>   if v[x,y] then ok:=false
>   else
>   begin
>     vv:=true;
>     if init(x+1,y) then if (a[x+1,y]<a[x,y]) and not(v[x+1,y]) then vv:=false;
>     if init(x-1,y) then if (a[x-1,y]<a[x,y]) and not(v[x-1,y]) then vv:=false;
>     if init(x,y+1) then if (a[x,y+1]<a[x,y]) and not(v[x,y+1]) then vv:=false;
>     if init(x,y-1) then if (a[x,y-1]<a[x,y]) and not(v[x,y-1]) then vv:=false;
>     ok:=vv;
>   end;
> end;
> begin
>   read(r,c);
>   for i:=1 to r do
>   for j:=1 to c do
>   begin
>     read(a[i,j]);
>     v[i,j]:=false;
>   end;
>   tot:=0;
>   for i:=1 to r do
>   for j:=1 to c do
>   begin
>     if d(i,j) then
>     begin
>       v[i,j]:=true;
>       f[i,j]:=1;
>       inc(tot);
>     end;
>   end;
>   while tot<r*c do
>   begin
>     for i:=1 to r do
>     for j:=1 to c do
>     begin
>       if ok(i,j) then
>       begin
>         v[i,j]:=true;
>         t:=0;
>         if init(i,j+1) then if v[i,j+1] and (a[i,j+1]<a[i,j]) then t:=max(t,f[i,j+1]);
>         if init(i,j-1) then if v[i,j-1] and (a[i,j-1]<a[i,j]) then t:=max(t,f[i,j-1]);
>         if init(i+1,j) then if v[i+1,j] and (a[i+1,j]<a[i,j]) then t:=max(t,f[i+1,j]);
>         if init(i-1,j) then if v[i-1,j] and (a[i-1,j]<a[i,j]) then t:=max(t,f[i-1,j]);
>         f[i,j]:=t+1;
>         inc(tot);
>       end;
>     end;
>   end;
>   ans:=0;
>   for i:=1 to r do
>   for j:=1 to c do
>   begin
>     if f[i,j]>ans then ans:=f[i,j];
>   end;
>   writeln(ans);
> end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator