Cod sursa(job #728163)

Utilizator alex45meOlaru Alex alex45me Data 28 martie 2012 15:34:16
Problema Cele mai apropiate puncte din plan Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 2.24 kb
type vect=record
   x,y:longint;
end;
type vector=array[1..100000] of vect;
var v:vector;
    i,n:longint;
    min:real;

procedure qsort2(var a : vector);

    procedure sort(l,r: longint);
      var
         i,j: longint;
         x,y:vect;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while (a[i].y<x.y)or((a[i].y<x.y)and(a[i].x<x.x)) do
            inc(i);
           while (x.y<a[j].y)or((a[j].y>x.y)and(a[j].x>x.x)) do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;

    begin
       sort(1,max);
    end;


procedure qsort1(var a :vector);
                             procedure sort(l,r: longint);
      var
         i,j: longint;
         x,y:vect;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while (a[i].x<x.x)or((a[i].x<x.x)and(a[i].y<x.y)) do
            inc(i);
           while (x.x<a[j].x)or((a[j].x>x.y)and(a[j].y>x.y)) do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;

    begin
       sort(1,max);
    end;


function dist(a,b,c,d:longint):real;
var x1,y1:int64;
begin
x1:=abs(a-c)*abs(a-c)
y1:=abs(b-d)*abs(b-d);
dist:=sqrt(x1+y1);
end;


begin
assign(input,'cmap.in');reset(input);
assign(output,'cmap.out');rewrite(output);
read(n);
for i:=1 to n do
    read(v[i].x,v[i].y);
qsort1(v);
min:=10000000000000000000000000;
for i:=1 to n-1  do
   if dist(v[i].x,v[i].y,v[i+1].x,v[i+1].y)<min then min:=dist(v[i].x,v[i].y,v[i+1].x,v[i+1].y);
qsort2(v);
for i:=1 to n-1  do
   if dist(v[i].x,v[i].y,v[i+1].x,v[i+1].y)<min then min:=dist(v[i].x,v[i].y,v[i+1].x,v[i+1].y);
write(min:0:6);
close(output);
end.