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 1111. Squares

Why my program got WA?
Posted by Vokin Andrei (vokin_andrei@mail.ru) 9 Feb 2002 12:44
const
  InputFile='Input.txt';
  OutputFile='Output.txt';
  MaxP=4;
  MaxN=101;
  _Eps=1e-15;
  _EpsSort=1e-14;
type
  Real=Extended;
  TPoint=record
    X,Y:Real;
  end;
  TLine=record
    A,B,C:Real;
  end;
  TPoly=record
    N:Integer;
    T:array[1..MaxP+1]of TPoint;
  end;
  TCircle=record
    R:Real;
    C:TPoint;
  end;
  TArrayPoly=array[1..MaxN]of TPoly;
  TArrayInt=array[1..MaxN]of Integer;
  TArrayReal=array[1..MaxN]of Real;
var
  T:TPoint;
  N:Integer;
  P:TArrayPoly;
  Numb:TArrayInt;
  DIst:TArrayReal;
function Rast(const T1,T2:TPoint):Real;
begin
  Rast:=Sqrt(Sqr(T1.x-T2.x)+Sqr(T1.y-T2.y));
end;
function Square(const P:TPoly):Real;
var
  I:Integer;
  S:Real;
begin
  s:=0.0;
  for i:=1 to P.n do
    s:=s+P.T[i+1].x*P.T[i].y-P.T[i].x*P.T[i+1].y;
  if(Abs(s)<_Eps)then
    s:=0.0;
  Square:=Abs(s)/2;
end;
function PointInsidePoly(const T:TPoint;const P:TPoly):Boolean;
var
  I:Integer;
  S:Real;
  Tr:TPoly;
begin
  s:=Square(P);
  Tr.n:=3;
  Tr.T[1]:=T;
  Tr.T[4]:=T;
  for i:=1 to P.n do begin
    Tr.T[2]:=P.T[i];
    Tr.T[3]:=P.T[i+1];
    s:=s-Square(Tr);
  end;
  PointInsidePoly:=Abs(s)<_Eps;
end;
procedure GetLineByPoints(const T1,T2:TPoint;var L:TLine);
begin
  L.A:=T2.y-T1.y;
  L.B:=T1.x-T2.x;
  L.C:=T2.x*T1.y-T1.x*T2.y;
  if(Abs(L.C)<_Eps)then
    L.C:=0.0;
end;
procedure GetNormal(const T:TPoint;const L:TLine;var N:TLine);
begin
  N.A:=L.B;
  N.B:=-L.A;
  N.C:=L.A*T.y-L.B*T.x;
  if(Abs(N.C)<_Eps)then
    N.C:=0.0;
end;
function PointInOtr(const T,Tb,Te:TPoint):Boolean;
begin
  PointInOtr:=False;
  if((Tb.x-_Eps<T.x)and(T.x<Te.x+_Eps))or((Te.x-_Eps<T.x)and
(T.x<Tb.x+_Eps))then
    if((Tb.y-_Eps<T.y)and(T.y<Te.y+_Eps))or((Te.y-_Eps<T.y)and
(T.y<Tb.y+_Eps))then
      PointInOtr:=True;
end;
function GetCrossLines(const L1,L2:Tline;var T:TPoint):Boolean;
var
  Del:Real;
begin
  Del:=L1.A*L2.B-L2.A*L1.B;
  if(Abs(Del)>_Eps)then begin
    GetCrossLines:=True;
    T.x:=-(L1.C*L2.B-L2.C*L1.B)/Del;
    T.y:=-(L1.A*L2.C-L2.A*L1.C)/Del;
    if(Abs(T.x)<_Eps)then
      T.x:=0.0;
    if(Abs(T.y)<_Eps)then
      T.y:=0.0;
  end else
    GetCrossLines:=False;
end;
function SolveSqrUr(const A,B,C:Real;var X1,X2:Real):Boolean;
var
  D:Real;
begin
  d:=Sqr(b)-4*a*c;
  if(d+_Eps>0.0)then begin
    SolveSqrUr:=True;
    x1:=(-b-Sqrt(Abs(d)))/(2*a);
    x2:=(-b+Sqrt(Abs(d)))/(2*a);
    if(Abs(x1)<_Eps)then
      x1:=0.0;
    if(Abs(x2)<_Eps)then
      x2:=0.0;
  end else
    SolveSqrUr:=False;
end;
function GetCrossLineCircle(const L:TLine;const C:TCircle;var
T1,T2:TPoint):Boolean;
var
  K,M:Real;
  Possible:Boolean;
begin
  if(Abs(L.B)>_Eps)then begin
    k:=L.A/L.B;
    m:=L.C/L.B+C.C.y;
    Possible:=SolveSqrUr(1+Sqr(k),2*(k*m-C.C.x),Sqr(C.C.x)+Sqr(m)-Sqr
(C.R),T1.x,T2.x);
    GetCrossLineCircle:=Possible;
    if(Possible)then begin
      T1.y:=-k*T1.x-L.C/L.B;
      T2.y:=-k*T2.x-L.C/L.B;
      if(Abs(T1.y)<_Eps)then
        T1.y:=0.0;
      if(Abs(T2.y)<_Eps)then
        T2.y:=0.0;
    end;
  end else begin
    k:=L.B/L.A;
    m:=L.C/L.A+C.C.x;
    Possible:=SolveSqrUr(1+Sqr(k),2*(k*m-C.C.y),Sqr(C.C.y)+Sqr(m)-Sqr
(C.R),T1.y,T2.y);
    GetCrossLineCircle:=Possible;
    if(Possible)then begin
      T1.x:=-k*T1.y-L.C/L.A;
      T2.x:=-k*T2.y-L.C/L.A;
      if(Abs(T1.x)<_Eps)then
        T1.x:=0.0;
      if(Abs(T2.x)<_Eps)then
        T2.x:=0.0;
    end;
  end;
end;
procedure ReHash(const T1,T2:TPoint;var P:TPoly);
var
  C:TCircle;
  L,N:TLine;
begin
  FillChar(P,SizeOf(P),0);
  C.C.x:=(T1.x+T2.x)/2;
  C.C.y:=(T1.y+T2.y)/2;
  C.R:=Rast(C.C,T1);
  GetLineByPoints(T1,T2,L);
  GetNormal(C.C,L,N);
  P.n:=4;
  P.T[1]:=T1;
  P.T[3]:=T2;
  P.T[5]:=T1;
  GetCrossLineCircle(N,C,P.T[2],P.T[4]);
end;
function
Use standart Input\OutPut and you get IFO
Posted by Nazarov Denis (nsc2001@rambler.ru) 9 Feb 2002 18:06
> const
>   InputFile='Input.txt';
>   OutputFile='Output.txt';
>   MaxP=4;
>   MaxN=101;
>   _Eps=1e-15;
>   _EpsSort=1e-14;
> type
>   Real=Extended;
>   TPoint=record
>     X,Y:Real;
>   end;
>   TLine=record
>     A,B,C:Real;
>   end;
>   TPoly=record
>     N:Integer;
>     T:array[1..MaxP+1]of TPoint;
>   end;
>   TCircle=record
>     R:Real;
>     C:TPoint;
>   end;
>   TArrayPoly=array[1..MaxN]of TPoly;
>   TArrayInt=array[1..MaxN]of Integer;
>   TArrayReal=array[1..MaxN]of Real;
> var
>   T:TPoint;
>   N:Integer;
>   P:TArrayPoly;
>   Numb:TArrayInt;
>   DIst:TArrayReal;
> function Rast(const T1,T2:TPoint):Real;
> begin
>   Rast:=Sqrt(Sqr(T1.x-T2.x)+Sqr(T1.y-T2.y));
> end;
> function Square(const P:TPoly):Real;
> var
>   I:Integer;
>   S:Real;
> begin
>   s:=0.0;
>   for i:=1 to P.n do
>     s:=s+P.T[i+1].x*P.T[i].y-P.T[i].x*P.T[i+1].y;
>   if(Abs(s)<_Eps)then
>     s:=0.0;
>   Square:=Abs(s)/2;
> end;
> function PointInsidePoly(const T:TPoint;const P:TPoly):Boolean;
> var
>   I:Integer;
>   S:Real;
>   Tr:TPoly;
> begin
>   s:=Square(P);
>   Tr.n:=3;
>   Tr.T[1]:=T;
>   Tr.T[4]:=T;
>   for i:=1 to P.n do begin
>     Tr.T[2]:=P.T[i];
>     Tr.T[3]:=P.T[i+1];
>     s:=s-Square(Tr);
>   end;
>   PointInsidePoly:=Abs(s)<_Eps;
> end;
> procedure GetLineByPoints(const T1,T2:TPoint;var L:TLine);
> begin
>   L.A:=T2.y-T1.y;
>   L.B:=T1.x-T2.x;
>   L.C:=T2.x*T1.y-T1.x*T2.y;
>   if(Abs(L.C)<_Eps)then
>     L.C:=0.0;
> end;
> procedure GetNormal(const T:TPoint;const L:TLine;var N:TLine);
> begin
>   N.A:=L.B;
>   N.B:=-L.A;
>   N.C:=L.A*T.y-L.B*T.x;
>   if(Abs(N.C)<_Eps)then
>     N.C:=0.0;
> end;
> function PointInOtr(const T,Tb,Te:TPoint):Boolean;
> begin
>   PointInOtr:=False;
>   if((Tb.x-_Eps<T.x)and(T.x<Te.x+_Eps))or((Te.x-_Eps<T.x)and
> (T.x<Tb.x+_Eps))then
>     if((Tb.y-_Eps<T.y)and(T.y<Te.y+_Eps))or((Te.y-_Eps<T.y)and
> (T.y<Tb.y+_Eps))then
>       PointInOtr:=True;
> end;
> function GetCrossLines(const L1,L2:Tline;var T:TPoint):Boolean;
> var
>   Del:Real;
> begin
>   Del:=L1.A*L2.B-L2.A*L1.B;
>   if(Abs(Del)>_Eps)then begin
>     GetCrossLines:=True;
>     T.x:=-(L1.C*L2.B-L2.C*L1.B)/Del;
>     T.y:=-(L1.A*L2.C-L2.A*L1.C)/Del;
>     if(Abs(T.x)<_Eps)then
>       T.x:=0.0;
>     if(Abs(T.y)<_Eps)then
>       T.y:=0.0;
>   end else
>     GetCrossLines:=False;
> end;
> function SolveSqrUr(const A,B,C:Real;var X1,X2:Real):Boolean;
> var
>   D:Real;
> begin
>   d:=Sqr(b)-4*a*c;
>   if(d+_Eps>0.0)then begin
>     SolveSqrUr:=True;
>     x1:=(-b-Sqrt(Abs(d)))/(2*a);
>     x2:=(-b+Sqrt(Abs(d)))/(2*a);
>     if(Abs(x1)<_Eps)then
>       x1:=0.0;
>     if(Abs(x2)<_Eps)then
>       x2:=0.0;
>   end else
>     SolveSqrUr:=False;
> end;
> function GetCrossLineCircle(const L:TLine;const C:TCircle;var
> T1,T2:TPoint):Boolean;
> var
>   K,M:Real;
>   Possible:Boolean;
> begin
>   if(Abs(L.B)&g