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

我郁闷了……帮忙看看哪里错了

Posted by BYF at 2005-03-30 20:29:14 on Problem 1088
WA的程序:

Program PKU1088;
Const
     Go:Array[1..4, 1..2] Of Longint=((1, 0), (0, 1), (-1, 0), (0, -1));
Var
   Map:Array[1..100, 1..100] Of Longint;
   F:Array[1..100, 1..100] Of Longint;
   R, C, I, J, Max, X, Y, K, T:Longint;

   Function Search(Y, X:Longint):Longint;
   Var
      I, NowX, NowY:Longint;
      J, K:Longint;
   Begin
        If F[Y, X]<>0 Then
        Begin
             Search:=F[Y, X];
             Exit;
        End;
        J:=0;
        For I:=1 To 4 Do
        Begin
             NowY:=Go[I, 1]+Y;
             NowX:=Go[I, 2]+X;
             If (NowX>=1) And (NowY>=1) And (NowX<=C) And (NowY<=R)
             And(Map[Y, X]>Map[NowY, NowX]) Then
             Begin
                  K:=Search(NowY, NowX)+1;
                  If K>J Then J:=K;
             End;
        End;
        Search:=J;
        F[Y, X]:=J;
   End;

Begin
//     Assign(input, 'ski.in');
//     Reset(Input);

     While Not Eof Do
     Begin
          FillChar(F, SizeOf(F), 0);
          Readln(R, C);
          For I:=1 To R Do
          Begin
               For J:=1 To C Do Read(Map[I, J]);
               Readln;
          End;

          For I:=1 To R Do
              For J:=1 To C Do
              Begin
                   T:=0;
                   For K:=1 To 4 Do
                   Begin
                        Y:=Go[K, 1]+I;
                        X:=Go[K, 2]+J;
                        If (Y>=1) And (X>=1) And (Y<=R) And (X<=C) Then
                           If Map[I, J]>Map[Y, X] Then Inc(T);
                   End;
                   If T=0 Then F[I, J]:=1;
              End;

          For I:=1 To R Do
              For J:=1 To C Do
                  If F[I, J]=0 Then Search(I, J);

          Max:=0;
          For I:=1 To R Do
              For J:=1 To C Do
                  If F[I, J]>Max Then Max:=F[I, J];
          Writeln(Max);
     End;

//     Close(input);
End.



TLE的程序(不是我编的):
program ski;

const
  max_size = 200;
  dr: array [1..4] of longint = (-1, 1, 0, 0);
  dc: array [1..4] of longint = (0, 0, -1, 1);

var
  row, col: longint;
  point: longint;
  height, len: array [1..max_size, 1..max_size] of longint;
  inq: array [1..max_size, 1..max_size] of boolean;
  queue: array [0..max_size * max_size, 1..2] of longint;
  head, tail: longint;
  r1, c1, r2, c2, k, i, j: longint;

procedure Enq(r, c, newl: longint);
begin
  if newl > len[r, c] then
  begin
    len[r, c] := newl;
    if not inq[r, c] then
    begin
      Inc(tail);
      if tail > point then tail := 0;
      queue[tail, 1] := r;
      queue[tail, 2] := c;
      inq[r, c] := true;
    end;
  end;
end;

begin
//    Assign(input, 'ski.in');
//    Reset(input);
    While not Eof Do
    Begin

  Readln(row, col);
  for i := 1 to row do
  begin
    for j := 1 to col do
      Read(height[i, j]);
    readln;
  End;

  { Initialize queue and len }
  point := row * col;
  head := 0;
  tail := 0;
  FillChar(inq, SizeOf(inq), false);
  FillChar(len, SizeOf(len), 0);
  for i := 1 to row do
    for j := 1 to col do
      Enq(i, j, 1);

  { Find the longest run }
  while head <> tail do
  begin
    Inc(head);
    if head > point then head := 0;
    r1 := queue[head, 1];
    c1 := queue[head, 2];
    inq[r1, c1] := false;
    for k := 1 to 4 do
    begin
      r2 := r1 + dr[k];
      c2 := c1 + dc[k];
      if (r2 > 0) and (c2 > 0) and (r2 <= row) and (c2 <= col) then
        if height[r2, c2] > height[r1, c1] then
          Enq(r2, c2, len[r1, c1] + 1);
    end;
  end;

  { Output }
  k := 0;
  for i := 1 to row do
    for j := 1 to col do
      if len[i, j] > k then k := len[i, j];
  Writeln(k);

  End;
//  Close(input);
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