ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1254. Die Hard

Why I always get CRASH? Please help me.
Posted by BYF 25 Aug 2003 18:34
This is my program.

Program Ural1254;
  Const
    Up:Array[1..8, 1..2] Of Integer=((1, 0), (0, 1), (-1, 0), (0, -1),
                                     (1, 1), (1, -1), (-1, 1), (-1, -
1));
  Type
    Rec=Record
          X, Y:Byte;
          Long:Real;
        End;
  Var
    P2, V:Real;
    M, N, K:Integer;
    Map:Array[1..75, 1..75] Of Char;
    Bomb:Array[0..1000, 1..2] Of Integer;
    Buf:Array[1..5625] Of Rec;
    Gone:Array[1..75, 1..75] Of Boolean;

  Procedure Init;
    Var
      A, B:Integer;
    Begin
      P2:=Sqrt(2);
      Readln(M, N, K, V);
      For A:=1 To N Do
        Begin
          For B:=1 To M Do Read(Map[A, B]);
          Readln;
        End;
      Readln(Bomb[0, 1], Bomb[0, 2]);
      For A:=1 To K Do Readln(Bomb[A, 1], Bomb[A, 2]);
    End;

  Procedure Main;
    Var
      Where, Step, NowFa:Integer;
      Done:Boolean;
      Total:Real;

    Procedure Search;
      Var
        A, NowX, NowY:Integer;

      Function OK(X, Y:Integer):Boolean;
        Begin
          If (X>0) And (Y>0) And (X<=M) And (Y<=N) And Not Gone[Y, X]
          And(Map[Y, X]='.') Then OK:=True
            Else OK:=False;
        End;

      Begin
        For A:=1 To 8 Do
          Begin
            NowX:=Buf[NowFa].X+Up[A, 1];
            NowY:=Buf[NowFa].Y+Up[A, 2];
            If OK(NowX, NowY) Then
              Begin
                Gone[NowY, NowX]:=True;
                Inc(Step);
                Buf[Step].X:=NowX;
                Buf[Step].Y:=NowY;
                If A>4 Then Buf[Step].Long:=Buf[NowFa].Long+P2
                  Else Buf[Step].Long:=Buf[NowFa].Long+1;
                If (NowX=Bomb[Where+1, 1]) And (NowY=Bomb[Where+1,
2]) Then
                  Begin
                    Done:=True;
                    Exit;
                  End;
              End;
          End;
      End;

    Begin
      Total:=0;
      For Where:=0 To K-1 Do
        Begin
          FillChar(Buf, SizeOf(Buf), 0);
          FillChar(Gone, SizeOf(Gone), False);
          NowFa:=1;
          Step:=1;
          Buf[NowFa].X:=Bomb[Where, 1];
          Buf[NowFa].Y:=Bomb[Where, 2];
          Gone[Bomb[Where, 2], Bomb[Where, 1]]:=True;
          Done:=False;
          Repeat
            Search;
            Inc(NowFa);
          Until Done;
          Total:=Total+Buf[Step].Long;
        End;
      Writeln(Total/V:0:2);
    End;

  Begin
    Init;
    Main;
  End.