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 had puzzle,why I got WA?Can you help me~
Posted by Zieve Cheng 28 Jun 2004 13:53
{}{$N+}
{}
{}program P1111;
{}
{}{Squares}
{}
{}type Zieve=array[1..4] of record
{----------------------------}x,y:double;
{--------------------------}end;
{}
{}var n:integer;
{----}x0,y0:double;
{----}list:array[1..100] of integer;
{----}l:array[1..100] of double;
{----}cr:array[1..100] of Zieve;
{}
{-}procedure change(var a,b:double);
{}
{-}var c:double;
{}
{-}begin
{}
{---}c:=a;
{---}a:=b;
{---}b:=c;
{}
{-}end;
{}
{-}procedure init;
{}
{-}var i:integer;
{-----}x1,x2,y1,y2:double;
{}
{-}begin
{}
{---}read(n);
{---}for i:=1 to n do
{---}begin
{-----}read(x1,y1,x2,y2);
{-----}if x1>x2 then change(x1,x2);
{-----}if y1>y2 then change(y1,y2);
{-----}cr[i,1].x:=x1;
{-----}cr[i,1].y:=y1;
{-----}cr[i,2].x:=x1;
{-----}cr[i,2].y:=y2;
{-----}cr[i,3].x:=x2;
{-----}cr[i,3].y:=y1;
{-----}cr[i,4].x:=x2;
{-----}cr[i,4].y:=y2;
{---}end;
{---}read(x0,y0);
{}
{-}end;
{}
{-}function long(z:Zieve):double;
{}
{-}var r,min:double;
{-----}i:integer;
{}
{-}begin
{}
{---}if (x0>=z[1].x)and(x0<=z[4].x)and
{------}(y0>=z[1].y)and(y0<=z[4].y) then min:=0 else
{---}begin
{-----}min:=1e+30;
{-----}if (x0>=z[1].x)and(x0<=z[4].x) then
{-----}begin
{-------}r:=sqr(z[1].y-y0);
{-------}if r<min then min:=r;
{-------}r:=sqr(z[4].y-y0);
{-------}if r<min then min:=r;
{-----}end
{-----}else
{-----}if (y0>=z[1].y)and(y0<=z[4].y) then
{-----}begin
{-------}r:=sqr(z[1].x-x0);
{-------}if r<min then min:=r;
{-------}r:=sqr(z[4].x-x0);
{-------}if r<min then min:=r;
{-----}end
{-----}else
{-----}begin
{-------}for i:=1 to 4 do
{-------}begin
{---------}r:=sqr(z[i].x-x0)+sqr(z[i].y-y0);
{---------}if r<min then min:=r;
{-------}end;
{-----}end;
{---}end;
{}
{---}long:=min;
{}
{-}end;
{}
{-}procedure main;
{}
{-}var i,j,k:integer;
{}
{-}begin
{}
{---}for i:=1 to n do
{---}begin
{-----}list[i]:=i;
{-----}l[i]:=long(cr[i]);
{---}end;
{}
{---}for i:=1 to n-1 do
{---}begin
{-----}k:=i;
{-----}for j:=i+1 to n do
{-------}if (l[list[k]]>l[list[j]])or((abs(l[list[k]]-l[list[j]])<1e-14)and(list[k]>list[j])) then k:=j;
{-----}j:=list[k];
{-----}list[k]:=list[i];
{-----}list[i]:=j;
{---}end;
{}
{---}for i:=1 to n do write(list[i],' ');
{}
{-}end;
{}
{}begin
{}
{--}init;
{--}main;
{}
{}end.

Edited by author 28.06.2004 14:01
Funny problem (+)
Posted by Dmitry 'Diman_YES' Kovalioff 28 Jun 2004 18:44
The sides of square can be not parallel to the axes, i.e. square 0 0 1 0 is possible :)
Re: Funny problem (+)
Posted by Zieve Cheng 29 Jun 2004 19:05
Thanks~~