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

No subject
Posted by Jet Li 24 Oct 2009 15:42
why i'm getting WA2?

here is my code

program acm_1111_1;

label W;

const Eps=1e-15;

type
 Square=record
 X1,Y1,X3,Y3:real;
 X2,Y2,X4,Y4:real;
end;

type
 Point=record
 X,Y:real;
end;

var p:array[1..100] of Square;
    Dis:array[1..100] of real;
    ID:array[1..100] of integer;
    Q,O:Point;
    r,sd1,sd2,sd3,sd4,vd1,vd2,vd3,vd4:real;
    Dist:real;
    i,j,kk,n:integer;

function L1_2(i:integer; A:Point; B:Point):real;
var a1,b1:real;
begin
 a1:=p[i].X2-p[i].X1;  b1:=p[i].Y2-p[i].Y1;
 L1_2:=a1*(B.X-A.X)-b1*(B.Y-A.Y);
end;

function L1_4(i:integer; A:Point; B:Point):real;
var a1,b1:real;
begin
 a1:=p[i].X4-p[i].X1;  b1:=p[i].Y4-p[i].Y1;
 L1_4:=a1*(B.X-A.X)-b1*(B.Y-A.Y);
end;

function min(aa,bb,cc,dd:real):real;
var mn:real;
begin
 mn:=aa;
 if bb<mn then mn:=aa;
 if cc<mn then mn:=cc;
 if dd<mn then mn:=dd;
 min:=mn;
end;

begin
  read(n);
  for i:=1 to n do
  begin
   read(p[i].X1,p[i].Y1,p[i].X3,p[i].Y3);
   O.X:=(p[i].X1+p[i].X3)/2; O.Y:=(p[i].Y1+p[i].Y3)/2;
   r:=sqrt(sqr(p[i].X1-p[i].X3)+sqr(p[i].Y1-p[i].Y3))/2;
   p[i].X2:=-(p[i].Y1-p[i].Y3)/2+O.X;
   p[i].Y2:=(p[i].X1-p[i].X3)/2+O.Y;
   p[i].X4:=(p[i].Y1-p[i].Y3)/2+O.X;
   p[i].Y4:=-(p[i].X1-p[i].X3)/2+O.Y;
  end;
  read(Q.X,Q.Y);

  for i:=1 to n do
  begin
   r:=sqrt(sqr(p[i].X1-p[i].X2)+sqr(p[i].Y1-p[i].Y2));

   vd1:=sqrt(sqr(Q.X-p[i].X1)+sqr(Q.Y-p[i].Y1));
   vd2:=sqrt(sqr(Q.X-p[i].X2)+sqr(Q.Y-p[i].Y2));
   vd3:=sqrt(sqr(Q.X-p[i].X3)+sqr(Q.Y-p[i].Y3));
   vd4:=sqrt(sqr(Q.X-p[i].X4)+sqr(Q.Y-p[i].Y4));

   O.X:=p[i].X1;  O.Y:=p[i].Y1;
   sd1:=abs(L1_4(i,Q,O))/r;   sd2:=abs(L1_2(i,Q,O))/r;
   O.X:=p[i].X3;  O.Y:=p[i].Y3;
   sd3:=abs(L1_4(i,O,Q))/r;  sd4:=abs(L1_2(i,O,Q))/r;

   if (abs(sd1)<Eps) or (abs(sd2)<Eps) or (abs(sd3)<Eps) or (abs(sd4)<Eps) then
   begin
    Dist:=min(vd1,vd2,vd3,vd4);
    goto W;
   end;

   if abs(sd1+sd3-r)<Eps then
   begin
    if abs(sd2+sd4-r)<Eps then begin Dist:=0; end;
    if abs(sd2-sd4-r)<Eps then begin Dist:=sd4; end;
    if abs(-sd2+sd4-r)<Eps then begin Dist:=sd2; end;
   end;

   if abs(sd1-sd3-r)<Eps then
   begin
    if abs(sd2+sd4-r)<Eps then begin Dist:=sd3; end;
    if abs(sd2-sd4-r)<Eps then begin Dist:=sd2; end;
    if abs(-sd2+sd4-r)<Eps then begin Dist:=vd2; end;
   end;

   if abs(-sd1+sd3-r)<Eps then
   begin
    if abs(sd2+sd4-r)<Eps then begin Dist:=sd1; end;
    if abs(sd2-sd4-r)<Eps then begin Dist:=vd4; end;
    if abs(-sd2+sd4-r)<Eps then begin Dist:=vd1; end;
   end;

W: Dis[i]:=abs(Dist);
   ID[i]:=i;
  end;

  for i:=1 to n-1 do
  for j:=i+1 to n do
  begin
   if Eps<Dis[i]-Dis[j] then
   begin
    Dist:=Dis[i];  Dis[i]:=Dis[j];  Dis[j]:=Dist;
    kk:=ID[i]; ID[i]:=ID[j];  ID[j]:=kk;
   end;
   if abs(Dis[i]-Dis[j])<=Eps then
   if ID[i]>ID[j] then
   begin
    kk:=ID[i]; ID[i]:=ID[j];  ID[j]:=kk;
   end;
  end;

  for i:=1 to n do write(ID[i],' '); writeln;
end.

I'm not seeing any disadvantages.....
Can you help me.

Thanks in advance