Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Closest-pair-problem/PL-I/closest-pair-problem.pli
Normal file
32
Task/Closest-pair-problem/PL-I/closest-pair-problem.pli
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* Closest Pair Problem */
|
||||
closest: procedure options (main);
|
||||
declare n fixed binary;
|
||||
|
||||
get list (n);
|
||||
begin;
|
||||
declare 1 P(n),
|
||||
2 x float,
|
||||
2 y float;
|
||||
declare (i, ii, j, jj) fixed binary;
|
||||
declare (distance, min_distance initial (0) ) float;
|
||||
|
||||
get list (P);
|
||||
min_distance = sqrt( (P.x(1) - P.x(2))**2 + (P.y(1) - P.y(2))**2 );
|
||||
ii = 1; jj = 2;
|
||||
do i = 1 to n;
|
||||
do j = 1 to n;
|
||||
distance = sqrt( (P.x(i) - P.x(j))**2 + (P.y(i) - P.y(j))**2 );
|
||||
if distance > 0 then
|
||||
if distance < min_distance then
|
||||
do;
|
||||
min_distance = distance;
|
||||
ii = i; jj = j;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
put skip edit ('The minimum distance ', min_distance,
|
||||
' is between the points [', P.x(ii),
|
||||
',', P.y(ii), '] and [', P.x(jj), ',', P.y(jj), ']' )
|
||||
(a, f(6,2));
|
||||
end;
|
||||
end closest;
|
||||
Loading…
Add table
Add a link
Reference in a new issue