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

I don't know why I get Crash(FLT_INVALID_OPERATION).I know there's something wrong with the scentence which mark with {},but I don't know what is wrong.
Posted by zruiwen 20 Oct 2002 09:33
{$A+,B-,D+,E+,F-,G-,I+,L+,N+,O-,P-,Q-,R-,S+,T-,V+,X+,Y+}
{$M 65520,0,655360}
type uu=record
         x,y:extended;
        end;
var mindis:array[1..100] of extended;
    num:array[1..100] of integer;
    zuob:array[1..100,1..2,1..2] of uu;

a1,a2,b1,b2,c1,c11,c2,l1,l2,xx,yy,xp,yp,xj,yj,min,bc,mm,t:extended;
    n,i,j,k,bb,tt,a,b,c,d:integer;

procedure xyz(a1,b1,c1,a2,b2,c2:extended;var x,y:extended);
begin
 x:=(b1*c2-b2*c1)/(a1*b2-a2*b1);
 y:=(c1*a2-c2*a1)/(a1*b2-a2*b1);
end;

function distan(x1,y1,x2,y2:extended):extended;
begin
 distan:=sqrt(abs(sqr(x1-x2))+abs(sqr(y1-y2)));
end;

begin
 readln(n);
 for i:=1 to n do
 begin
  num[i]:=i;
  for j:=1 to 2 do read(zuob[i,1,j].x,zuob[i,1,j].y);
  a1:=zuob[i,1,1].y-zuob[i,1,2].y;
  b1:=zuob[i,1,2].x-zuob[i,1,1].x;
  c1:=(zuob[i,1,2].y-zuob[i,1,1].y)*zuob[i,1,2].x+(zuob[i,1,1].x-zuob
[i,1,2].x)*zuob[i,1,2].y;
  c11:=c1;
  l1:=distan(zuob[i,1,1].x,zuob[i,1,1].y,zuob[i,1,2].x,zuob
[i,1,2].y)/2;
  xx:=(zuob[i,1,1].x+zuob[i,1,2].x)/2;
  yy:=(zuob[i,1,1].y+zuob[i,1,2].y)/2;
  a2:=-b1;
  b2:=a1;
  c2:=-(a2*xx+b2*yy);
  c1:=c11-sqrt(a1*a1+b1*b1)*l1;
  xyz(a1,b1,c1,a2,b2,c2,zuob[i,2,1].x,zuob[i,2,1].y);
  c1:=c11+sqrt(a1*a1+b1*b1)*l1;
  xyz(a1,b1,c1,a2,b2,c2,zuob[i,2,2].x,zuob[i,2,2].y);
 end;
 readln(xp,yp);
 for i:=1 to n do
 begin
  bb:=0;
  mm:=1e+10;
  bc:=distan(zuob[i,1,1].x,zuob[i,1,1].y,zuob[i,1,2].x,zuob
[i,1,2].y)/2*sqrt(2);
  for a:=1 to 2 do
   for b:=1 to 2 do
    for c:=1 to 2 do
    if a<>c then
    for d:=1 to 2 do
    if (zuob[i,a,b].y<>zuob[i,c,d].y)or(zuob[i,c,d].x<>zuob[i,a,b].x)
then
    begin
     a1:=zuob[i,a,b].y-zuob[i,c,d].y;
     b1:=zuob[i,c,d].x-zuob[i,a,b].x;
     c1:=(zuob[i,c,d].y-zuob[i,a,b].y)*zuob[i,c,d].x+(zuob[i,a,b].x-
zuob[i,c,d].x)*zuob[i,c,d].y;
     a2:=-b1;
     b2:=a1;
     c2:=-(a2*xp+b2*yp);
 {    xj:=(b1*c2-b2*c1)/(a1*b2-a2*b1);
     yj:=(c1*a2-c2*a1)/(a1*b2-a2*b1);}
     if ((zuob[i,a,b].x-xj)*(zuob[i,c,d].x-xj)<=0)and
     ((zuob[i,a,b].y-yj)*(zuob[i,c,d].y-yj)<=0) then
     min:=distan(xp,yp,xj,yj) else
     begin
      l1:=distan(xp,yp,zuob[i,a,b].x,zuob[i,a,b].y);
      if l1<1e-14 then l1:=0;
      l2:=distan(xp,yp,zuob[i,c,d].x,zuob[i,c,d].y);
      if l1<l2 then min:=l1
               else min:=l2;
     end;
     if min>bc then bb:=1;
     if min<mm then mm:=min;
    end;
  if bb=0 then mm:=0;
  mindis[i]:=mm;
 end;
 for i:=1 to n-1 do
 begin
  k:=i;
  for j:=i+1 to n do
  if mindis[j]<mindis[k] then k:=j;
  if i<>k then
  begin
   t:=mindis[i];
   mindis[i]:=mindis[k];
   mindis[k]:=t;
   tt:=num[i];
   num[i]:=num[k];
   num[k]:=tt;
  end;
 end;
 for i:=1 to n do
 write(num[i],' ');
end.