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?Here's it.
Posted by Huang Yizheng 13 Nov 2001 15:28
const maxn=100;
      jin=1e-15;
var d:array [1..maxn] of extended;
    id:array [1..maxn] of byte;
    square:array [1..maxn] of
     record xmin,ymin,xmax,ymax:integer;end;
    n,i,k:byte;
    px,py:integer;
procedure swap(var a,b:integer);
var t:integer;
begin
 t:=a;a:=b;b:=t;
end;
procedure swapb(var a,b:byte);
var t:byte;
begin
 t:=a;a:=b;b:=t;
end;
procedure swapd(var a,b:extended);
var t:extended;
begin
 t:=a;a:=b;b:=t;
end;
function dis(x,y:integer):extended;
begin
 dis:=sqrt(sqr(px-x)+sqr(py-y));
end;
function min(a,b:integer):integer;
begin
 if a<b then min:=a else min:=b;
end;
function max(a,b:integer):integer;
begin
 if a>b then max:=a else max:=b;
end;
begin
 readln(n);
 for i:=1 to n do
  begin
   readln(square[i].xmin,square[i].ymin,square
[i].xmax,square[i].ymax);
   px:=max(abs(square[i].xmin-square[i].xmax),abs(square
[i].ymin-square[i].ymax));
   square[i].xmin:=min(square[i].xmin,square[i].xmax);
   square[i].ymin:=min(square[i].ymin,square[i].ymax);
   square[i].xmax:=square[i].xmin+px;
   square[i].ymax:=square[i].ymin+px;
  end;
 readln(px,py);
 for i:=1 to n do
  if px<square[i].xmin then
   if py<square[i].ymin then d[i]:=dis(square[i].xmin,square
[i].ymin)
  else
   if py<=square[i].ymax then d[i]:=square[i].xmin-px
  else d[i]:=dis(square[i].xmin,square[i].ymax)
 else
  if px<=square[i].xmax then
   if py<square[i].ymin then d[i]:=square[i].ymin-py
  else
   if py<=square[i].ymax then d[i]:=0
  else d[i]:=py-square[i].ymax
 else
  if py<square[i].ymin then d[i]:=dis(square[i].xmax,square
[i].ymin)
   else
  if py<=square[i].ymax then d[i]:=px-square[i].xmax
   else d[i]:=dis(square[i].xmax,square[i].ymax);
 for i:=1 to n do id[i]:=i;
 for i:=1 to n-1 do
  for k:=i+1 to n do
   if d[i]>d[k]+jin then
    begin
     swapd(d[i],d[k]);
     swapb(id[i],id[k]);
    end;
 for i:=1 to n-1 do
  write(id[i],' ');
 writeln(id[n]);
end.
Re: Why my program got WA?Here's it.
Posted by Nanyang Revenger 24 Nov 2001 14:41
It's a square. Not a rectangle.