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 1212. Battleship

Help! why Wrong Answer ?
Posted by XueMao 28 Mar 2003 18:51
Program Sea_Battle;

Var i,j,k,x,y,m,n,tot,ans:longint;
    d:array[1..30,1..4] of longint;
    a:array[1..2000,1..4] of longint;
    s:string;

Procedure Cut(x1,y1,x2,y2:longint);

Var i,j,k,L,bj,x,y:longint;
    xx,k1:longint;

Begin
  j:=0;
  k1:=tot;
  while j<k1 do
  begin
    inc(j);
    if (a[j,1]>=x1)and(a[j,2]>=y1)and
    (a[j,3]<=x2)and(a[j,4]<=y2) then
    begin
      for L:=1 to 4 do a[j,L]:=0;
    end
    else
    begin
      bj:=0;
      if (x1>=a[j,1])and(x1<=a[j,3])and
      (((y1>=a[j,2])and(y1<=a[j,4]))or
      ((y2>=a[j,2])and(y2<=a[j,4]))or
      ((y1<=a[j,2])and(y2>=a[j,4]))) then bj:=1;
      if (x2>=a[j,1])and(x2<=a[j,3])and
      (((y1>=a[j,2])and(y1<=a[j,4]))or
      ((y2>=a[j,2])and(y2<=a[j,4]))or
      ((y1<=a[j,2])and(y2>=a[j,4]))) then
      begin
        if bj=0 then bj:=2
        else
        begin
          inc(tot);
          a[tot]:=a[j];
          a[tot,1]:=x2+1;
        end;
      end;
      if (y1>=a[j,2])and(y1<=a[j,4])and
      (((x1>=a[j,1])and(x1<=a[j,3]))or
      ((x2>=a[j,1])and(x2<=a[j,3]))or
      ((x1<=a[j,1])and(x2>=a[j,3]))) then
      begin
        if (x1<=a[j,1])and(x2>=a[j,3])and(bj=0) then bj:=3
        else
        begin
          if x1<a[j,1] then x:=a[j,1]
          else x:=x1;
          if x2<a[j,3] then xx:=x2
          else xx:=a[j,3];
          inc(tot);
          a[tot]:=a[j];
          a[tot,1]:=x;
          a[tot,4]:=y1-1;
          a[tot,3]:=xx;
        end;
      end;
      if (y2>=a[j,2])and(y2<=a[j,4])and
      (((x1>=a[j,1])and(x1<=a[j,3]))or
      ((x2>=a[j,1])and(x2<=a[j,3]))or
      ((x1<=a[j,1])and(x2>=a[j,3]))) then
      begin
        if (x1<=a[j,1])and(x2>=a[j,3])and(bj=0) then bj:=4
        else
        begin
          if x1<a[j,1] then x:=a[j,1]
          else x:=x1;
          if x2<a[j,3] then xx:=x2
          else xx:=a[j,3];
          inc(tot);
          a[tot]:=a[j];
          a[tot,1]:=x;
          a[tot,2]:=y2+1;
          a[tot,3]:=xx;
        end;
      end;
      case bj of
      1:begin
          a[j,3]:=x1-1;
        end;
      2:begin
          a[j,1]:=x2+1;
        end;
      3:begin
          if x1<a[j,1] then x:=a[j,1]
          else x:=x1;
          if x2<a[j,3] then xx:=x2
          else xx:=a[j,3];
          a[j,1]:=x;
          a[j,4]:=y1-1;
          a[j,3]:=xx;
        end;
      4:begin
          if x1<a[j,1] then x:=a[j,1]
          else x:=x1;
          if x2<a[j,3] then xx:=x2
          else xx:=a[j,3];
          a[j,1]:=x;
          a[j,2]:=y2+1;
          a[j,3]:=xx;
        end
      end;
    end;
  end;
  inc(tot);
  a[tot,1]:=x1;
  a[tot,2]:=y1;
  a[tot,3]:=x2;
  a[tot,4]:=y2;
End;

Procedure Search(z:longint);
Var i,j,k,x1,y1,x2,y2:longint;
Begin
  for i:=1 to n do
  begin
    if z=1 then
    begin
      x1:=d[i,1]-1;
      y1:=d[i,2]-m;
      if d[i,4]=1 then x2:=d[i,1]+1
      else x2:=d[i,1]+d[i,3];
      if d[i,4]=0 then y2:=d[i,2]+1
      else y2:=d[i,2]+d[i,3];
    end
    else
    begin
      x1:=d[i,1]-m;
      y1:=d[i,2]-1;
      if d[i,4]=1 then x2:=d[i,1]+1
      else x2:=d[i,1]+d[i,3];
      if d[i,4]=0 then y2:=d[i,2]+1
      else y2:=d[i,2]+d[i,3];
    end;
    if x1<1 then x1:=1;
    if y1<1 then y1:=1;
    if x2>x then x2:=x;
    if y2>y then y2:=y;
    Cut(x1,y1,x2,y2);
  end;
  for i:=1 to tot do
  if (a[i,1]<>0)and((a[i,3]-a[i,1]+1)*
  (a[i,4]-a[i,2]+1)>0) then
  ans:=ans-(a[i,3]-a[i,1]+1)*
  (a[i,4]-a[i,2]+1);
End;

Begin
  readln(x,y,n);
  ans:=x*y*2;
  fillchar(d,
Mail me to dimanyes@mail.ru (-)
Posted by Dmitry 'Diman_YES' Kovalioff 28 Mar 2003 21:20
Re: Help! why Wrong Answer ?
Posted by I 31 May 2003 14:41
What's your iq?