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 1151. Radiobeacons

Why I got "wrong answer"? This is the program.Can anyone help me?
Posted by Lin 3 Oct 2002 15:16
Const MaxN      = 10;
      MaxSize   = 200;

Type TotalType  = Array[1..MaxN,1..MaxSize,1..MaxSize] of Byte;

Var  B          : ^TotalType;
     Id         : Array[1..MaxN] of Integer;
     T          : Array[1..MaxN] of Integer;
     N          : Integer;

Procedure FindPlace(X,Y,TheId,d : Integer);
Var i,j                         : Integer;
  Function GetNum : Integer;
    Var k         : Integer;
    Begin
      For k := 1 to N do
        If TheId=Id[k] then
          Begin
            GetNum := k;
            Exit;
          End;
      Inc(N); Id[N] := TheId;
      GetNum := N;
    End;
Begin
  i := GetNum; Inc(T[i]);
  For j := -d to d do
    Begin
      If (1<=X+d) and (X+d<=MaxSize) then
        If (1<=Y+j) and (Y+j<=MaxSize) then
          Inc(B^[i,X+d,Y+j]);
      If (1<=X-d) and (X-d<=MaxSize) then
        If (1<=Y+j) and (Y+j<=MaxSize) then
          Inc(B^[i,X-d,Y+j]);
    End;
  For j := -d+1 to d-1 do
    Begin
      If (1<=Y+d) and (Y+d<=MaxSize) then
        If (1<=X+j) and (X+j<=MaxSize) then
          Inc(B^[i,X+j,Y+d]);
      If (1<=Y-d) and (Y-d<=MaxSize) then
        If (1<=X+j) and (X+j<=MaxSize) then
          Inc(B^[i,X+j,Y-d]);
    End;
End;

Function ReadNum(Var X : String) : Integer;
Var Temp               : Longint;
Begin
  Temp := 0;
  While (Length(X)>0) and (X[1] in ['0'..'9']) do
    Begin
      Temp := Temp*10+Ord(X[1])-48;
      Delete(X,1,1);
    End;
  If Length(X)>0 then Delete(X,1,1);
  ReadNum := Temp;
End;

Procedure Main;
Var Total,i     : Integer;
    Str         : String;
    X,Y         : Integer;
    TheId,d     : Integer;
Begin
  Readln(Total);
  For i := 1 to Total do
    Begin
      Readln(Str);
      X := ReadNum(Str); Y := ReadNum(Str);
      While Length(Str)<>0 do
        Begin
          TheId := ReadNum(Str); d := ReadNum(Str);
          FindPlace(X,Y,TheId,d);
        End;
    End;
End;

Procedure Print;
Var i,j,k       : Integer;
    Total       : Integer;
    Place       : Array[1..MaxN,1..2] of Integer;
Begin
  Fillchar(Place,Sizeof(Place),0);
  For i := 1 to N do
    Begin
      Total := 0;
      For j := 1 to MaxSize do
        For k := 1 to MaxSize do
          If B^[i,j,k]=T[i] then
            Begin
              Inc(Total);
              Place[i,1] := j; Place[i,2] := k;
            End;
      If Total<>1 then
        Begin
          Place[i,1] := 0; Place[i,2] := 0;
        End;
    End;
  For j := 1 to 30000 do
    For i := 1 to N do
      If Id[i]=j then
        If Place[i,1]=0 then Writeln(j,':UNKNOWN')
                        else Writeln(j,':',Place[i,1],Chr(44),Place
[i,2]);
End;

Begin
  New(B);
  Fillchar(B^,Sizeof(B^),0);
    Main;
    Print;
  Dispose(B);
End.