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 I get WA? Pelase, help me!!!!!!! (+)
Posted by Nazarov Denis (nsc2001@rambler.ru) 26 Jan 2002 14:24
My program:

Program t1111;{$N+}

Var Dist         :array[1..101]of record v :extended; n:integer; end;
    S,SS         :array[1..100,1..4]of extended;
    P,PP         :record x,y :extended end;
    N,i,j        :integer;
    W,tgW        :extended;

Function R(x1,y1,x2,y2:extended):extended;
 begin
  R := sqrt ( sqr(x1-x2) + sqr(y1-y1) ) ;
 end;

Procedure Convert(x,y,w:extended;Var xi,yi:extended);
 begin
  xi:=x*cos(w)+y*sin(w);
  yi:=y*cos(w)-x*sin(w);
 end;

Function D(x1,y1,x2,y2:extended):extended;
var minX,maxX,minY,maxY :extended;
    d1,d2,d3,d4,dd      :extended;
 begin
  if x1>x2 then begin
   minX:=x2;
   maxX:=x1;
  end else begin
   minX:=x1;
   maxX:=x2;
  end;
  if y1>y2 then begin
   minY:=y2;
   maxY:=y1;
  end else begin
   minY:=y1;
   maxY:=y2;
  end;
  if ( minx < p.x ) and ( maxx > p.x ) and
     ( miny < p.y ) and ( maxy > p.y ) then D := 0 else
  if ( minx < p.x ) and ( maxx > p.x ) then begin
    if abs( p.y - miny ) < abs( p.y - maxy ) then
     D := abs( p.y - miny ) else D := abs( p.y - maxy ) ;
   end else
  if ( miny < p.y ) and ( maxy > p.y ) then begin
    if abs( p.x - minx ) < abs( p.x - maxx ) then
     D := abs( p.x - minx ) else D := abs( p.x - maxx ) ;
   end else begin
    d1:=r(minx,miny,p.x,p.y);
    d2:=r(minx,maxy,p.x,p.y);
    d3:=r(maxx,miny,p.x,p.y);
    d4:=r(maxx,maxy,p.x,p.y);
    dd:=d1;
    if dd>d2 then dd:=d2;
    if dd>d3 then dd:=d3;
    if dd>d4 then dd:=d4;
    d:=dd;
   end;
 end;

begin
read(N);
for i:=1 to N do
 for j:=1 to 4 do
  read(s[i,j]);
read(pp.x,pp.y);
for i:=1 to n do begin
 if abs(s[i,4]-s[i,2])>1E-10 then begin
  tgW:=(s[i,3]-s[i,1])/(s[i,4]-s[i,2]);
  W:=ArcTan(tgW);
 end else
  W:=90;
 W:=W-45;
 p.x:=pp.x*cos(W)+pp.y*sin(W);
 p.y:=-pp.x*sin(W)+pp.y*cos(W);
 convert(s[i,1],s[i,2],w,ss[i,1],ss[i,2]);
 convert(s[i,3],s[i,4],w,ss[i,3],ss[i,4]);
 dist[i].v:=d(ss[i,1],ss[i,2],ss[i,3],ss[i,4]);
end;
for i:=1 to n do dist[i].n:=i;
for i:=1 to n-1 do
 for j:=i+1 to n do
  if (dist[i].v-dist[j].v>1E-14)or((abs(dist[i].v-dist[j].v)<=1E-14)
and(dist[i].n>dist[j].n)) then begin
   dist[101]:=dist[i];
   dist[i]:=dist[j];
   dist[j]:=dist[101];
  end;
for i:=1 to n do write(dist[i].n,' ');writeln;
end.
Sorry, I wrote not last version of my program (+)
Posted by Nazarov Denis (nsc2001@rambler.ru) 26 Jan 2002 15:55
My program:

Program t1111;{$N+}

Const Change=180/3.14159265359;
      Eps=1E-14;

Var Dist         :array[1..101]of record v :extended; n:integer; end;
    S,SS         :array[1..100,1..4]of extended;
    P,PP         :record x,y :extended end;
    N,i,j        :integer;
    W,tgW        :extended;

Function R(x1,y1,x2,y2:extended):extended;
 begin
  R := sqrt ( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) ;
 end;

Procedure Convert(x,y,w:extended;Var xi,yi:extended);
 begin
  xi:=x*cos(w/Change)+y*sin(w/Change);
  yi:=y*cos(w/Change)-x*sin(w/Change);
 end;

Function D(x1,y1,x2,y2:extended):extended;
var minX,maxX,minY,maxY :extended;
    d1,d2,d3,d4,dd      :extended;
 begin
  if x1>x2 then begin
   minX:=x2;
   maxX:=x1;
  end else begin
   minX:=x1;
   maxX:=x2;
  end;
  if y1>y2 then begin
   minY:=y2;
   maxY:=y1;
  end else begin
   minY:=y1;
   maxY:=y2;
  end;
  if ( minx < p.x ) and ( maxx > p.x ) and
     ( miny < p.y ) and ( maxy > p.y ) then D := 0 else
  if ( minx < p.x ) and ( maxx > p.x ) then begin
    if abs( p.y - miny ) < abs( p.y - maxy ) then
     D := abs( p.y - miny ) else D := abs( p.y - maxy ) ;
   end else
  if ( miny < p.y ) and ( maxy > p.y ) then begin
    if abs( p.x - minx ) < abs( p.x - maxx ) then
     D := abs( p.x - minx ) else D := abs( p.x - maxx ) ;
   end else begin
    d1:=r(minx,miny,p.x,p.y);
    d2:=r(minx,maxy,p.x,p.y);
    d3:=r(maxx,miny,p.x,p.y);
    d4:=r(maxx,maxy,p.x,p.y);
    dd:=d1;
    if dd>d2 then dd:=d2;
    if dd>d3 then dd:=d3;
    if dd>d4 then dd:=d4;
    d:=dd;
   end;
 end;

begin
read(N);
for i:=1 to N do
 for j:=1 to 4 do
  read(s[i,j]);
read(pp.x,pp.y);
for i:=1 to n do begin
 if abs(s[i,4]-s[i,2])>1E-10 then begin
  tgW:=abs((s[i,3]-s[i,1])/(s[i,4]-s[i,2]));
  W:=ArcTan(tgW);
  W:=W*Change;
  if (s[i,3]-s[i,1]<0)and(s[i,4]-s[i,2]>0) then W:=180-W else
  if (s[i,3]-s[i,1]<0)and(s[i,4]-s[i,2]<0) then W:=180+W else
  if (s[i,3]-s[i,1]>0)and(s[i,4]-s[i,2]<0) then W:=-W;
 end else
  W:=90;
 W:=W-45;
 p.x:=pp.x*cos(W/Change)+pp.y*sin(W/Change);
 p.y:=-pp.x*sin(W/Change)+pp.y*cos(W/Change);
 convert(s[i,1],s[i,2],w,ss[i,1],ss[i,2]);
 convert(s[i,3],s[i,4],w,ss[i,3],ss[i,4]);
 dist[i].v:=d(ss[i,1],ss[i,2],ss[i,3],ss[i,4]);
end;
for i:=1 to n do dist[i].n:=i;
for i:=1 to n-1 do
 for j:=i+1 to n do
  if (dist[i].v-dist[j].v>Eps)or((abs(dist[i].v-dist[j].v)<Eps)and
(dist[i].n>dist[j].n)) then begin
   dist[101]:=dist[i];
   dist[i]:=dist[j];
   dist[j]:=dist[101];
  end;
for i:=1 to n do write(dist[i].n,' ');writeln;
end.