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

WA HELP PLEASE
Posted by Oleg 7 May 2003 17:53
var i,j,k,n,m:longint;
    a:array [1..100] of record x1,y1,x2,y2:integer; end;
    x,y:longint;
    r:array [0..100] of record r:real;i:integer; end;
function min(a,b:integer):integer; begin if a>b then min:=b else
min:=a; end;
function minr(a,b:real):real;      begin if a>b then minr:=b else
minr:=a;end;
function max(a,b:integer):integer; begin if a<b then max:=b else
max:=a; end;
function rr(x,y,x1,y1:Longint):real;begin rr:=sqrt(sqr(x-x1)+sqr(y-
y1)); end;
function inn(x1,x,x2:integer):boolean;
begin
if (min(x1,x2)<=x) and (x<=max(x1,x2)) then inn:=true else inn:=false;
end;

function r_kv_t(x1,y1,x2,y2:Longint):real;
var r1,r2,r3,r4:real;
begin
 if inn(x1,x,x2) and inn(y1,y,y2) then r_kv_t:=0 else
 begin
  if inn(x1,x,x2) then r_kv_t:=min(abs(y2-y),abs(y1-y));
  if inn(y1,y,y2) then r_kv_t:=min(abs(x2-x),abs(x1-x));
  r1:=rr(x1,y1,x,y);
  r2:=rr(x2,y2,x,y);
  r3:=rr(x1,y2,x,y);
  r4:=rr(x2,y1,x,y);
  r_kv_t:=minr(minr(r1,r2),minr(r3,r4));
 end;
end;

begin
 read(n);
 for i:=1 to n do read(a[i].x1,a[i].y1,a[i].x2,a[i].y2);
 read(x,y);
 for i:=1 to n do r[i].r:=r_kv_t(a[i].x1,a[i].y1,a[i].x2,a[i].y2);
 for i:=1 to n do r[i].i:=i;
 for i:=1 to n do
  for j:=i+1 to n do
  if r[i].r-r[j].r>1e-14 then
   begin
    r[0]:=r[i]; r[i]:=r[j]; r[j]:=r[0];
   end;
 for i:=1 to n-1 do write(r[i].i,' '); writeln(r[n].i);
end.
new : WA HELP PLEASE
Posted by Oleg 8 May 2003 09:49
var i,j,k,n,m:longint;
    a:array [1..100] of record x1,y1,x2,y2:integer; end;
    x,y:longint;
    r:array [0..100] of record r:real;i:integer; end;
function min(a,b:integer):integer; begin if a>b then min:=b else
min:=a; end;
function minr(a,b:real):real;      begin if a>b then minr:=b else
minr:=a;end;
function max(a,b:integer):integer; begin if a<b then max:=b else
max:=a; end;
function rr(x,y,x1,y1:Longint):real;begin rr:=sqrt(sqr(x-x1)+sqr(y-
y1)); end;
function inn(x1,x,x2:integer):boolean;
begin
if (min(x1,x2)<=x) and (x<=max(x1,x2)) then inn:=true else inn:=false;
end;

function r_kv_t(x1,y1,x2,y2:Longint):real;
var r1,r2,r3,r4:real;
begin
 if inn(x1,x,x2) and inn(y1,y,y2) then r_kv_t:=0 else
 begin
  if inn(x1,x,x2) then r_kv_t:=min(abs(y2-y),abs(y1-y)) else
  if inn(y1,y,y2) then r_kv_t:=min(abs(x2-x),abs(x1-x)) else begin
  r1:=rr(x1,y1,x,y);
  r2:=rr(x2,y2,x,y);
  r3:=rr(x1,y2,x,y);
  r4:=rr(x2,y1,x,y);
  r_kv_t:=minr(minr(r1,r2),minr(r3,r4));
  end;
 end;
end;

begin
 read(n);
 for i:=1 to n do read(a[i].x1,a[i].y1,a[i].x2,a[i].y2);
 read(x,y);
 for i:=1 to n do r[i].r:=r_kv_t(a[i].x1,a[i].y1,a[i].x2,a[i].y2);
 for i:=1 to n do r[i].i:=i;
 for i:=1 to n do
  for j:=i+1 to n do
  if r[i].r-r[j].r>1e-14 then
   begin
    r[0]:=r[i]; r[i]:=r[j]; r[j]:=r[0];
   end;
 for i:=1 to n-1 do write(r[i].i,' '); writeln(r[n].i);
end.