Cod sursa(job #37364)

Utilizator fogabFodor Gabor fogab Data 24 martie 2007 22:28:45
Problema Adapost 2 Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.91 kb
var f:text;
    x,y:array[0..50000] of extended;
    lrx,lry,rx,ry,jump:extended;
    h:array[0..4] of extended;
    n,i,j:word;
function get(rx,ry:extended):extended;
var i:word;
    sol:extended;
begin
  sol:=0;
  for i:=1 to n do
    sol:=sol+sqrt(sqr(rx-x[i])+sqr(ry-y[i]));
  get:=sol;
end;
begin
assign(f,'adapost2.in');
reset(f);
read(f,n);
for i:=1 to n do
  begin
  read(f,x[i],y[i]);
  rx:=rx+x[i];
  ry:=ry+y[i];
  end;
close(f);
rx:=rx/n;
ry:=ry/n;
h[0]:=get(rx,ry);
jump:=1000;
while (jump>0.00001) do
begin
h[1]:=get(rx+jump,ry);
h[2]:=get(rx-jump,ry);
h[3]:=get(rx,ry-jump);
h[4]:=get(rx,ry+jump);
j:=0;
for i:=1 to 4 do
  if h[i]<h[j] then j:=i;
h[0]:=h[j];
if j=1 then rx:=rx+jump;
if j=2 then rx:=rx-jump;
if j=3 then ry:=ry-jump;
if j=4 then ry:=ry+jump;
jump:=jump*4/5;
end;

assign(f,'adapost2.out');
rewrite(f);
writeln(f,rx:0:4,' ',ry:0:4);
close(f);
end.