Siguren sum deka algoritamot ne ti je tacno implementiran
pa ti producira poveke tocki odosto bi imal konveksniot omotac. Evo ti
moj kod, pa ga razgledaj:
Code:
program tacke;
uses math;
const maxn = 100000;
type point = record
x, y: longint;
t : double;
end;
var c, p, s: array [1..maxn] of point;
f: text;
n, m, i, j, kraj, min: longint;
r, max : double;
procedure input;
begin
assign (f, '');
reset (f);
readln (f, n);
for i:= 1 to n do
readln (f, c[i].x, c[i].y);
readln (f, m);
for i:= 1 to m do
readln (f, p[i].x, p[i].y);
close (f);
end;
procedure swap (var a, b: point);
var t: point;
begin
t:= a; a:= b; b:= t;
end;
function theta (p1, p2: point): double;
var dx, dy, ax, ay: longint;
t: double;
begin
dx:= p2.x - p1.x;
dy:= p2.y - p1.y;
ax:= abs (dx);
ay:= abs (dy);
if (dx = 0) and (dy = 0) then
t:= 0
else
t:= dy / (ax + ay);
if dx < 0 then
t:= 2 - t
else if dy < 0 then
t:= t + 4;
theta:= 90 * t;
end;
procedure sort (l, r: longint; var p: array of point);
var i, j: longint;
t, x: point;
begin
i:= l; j:= r;
x:= p[(l + r) div 2];
repeat
while (x.t>p[i].t) do inc (i);
while (x.t<p[j].t) do dec (j);
if i <= j then begin
swap (p[i], p[j]);
inc (i);
dec (j);
end;
until i > j;
if j > l then sort (l, j, p);
if i < r then sort (i, r, p);
end;
function levo (p1, p2, p: point): boolean;
var t: longint;
begin
t:= ((p.y - p1.y) * (p2.x - p1.x)) -
((p.x - p1.x) * (p2.y - p1.y));
levo:= t > 0;
end;
procedure push (a: point);
begin
inc (kraj);
s[kraj]:= a;
end;
procedure graham (var a: array of point; var n: longint; isc: boolean);
var br: longint;
t: point;
begin
for i:= 1 to n-1 do
if (a[min].y>a[i].y) or ((a[min].y=a[i].y) and (a[min].x>a[i].x)) then
min:= i;
swap (a[0], a[min]);
for i:= 1 to n-1 do
a[i].t:= theta (a[i], a[0]);
sort (1, n, a);
br:= 0;
i:= 1;
while i < n-1 do begin
inc (br);
t:= a[i];
j:= i+1;
while (j < n-1) and (a[j].t=t.t) do begin
if a[j].x > t.x then
t.x:= a[j].x;
inc (j);
end;
i:= j;
a[br]:= t;
end;
kraj:= 0;
min:= 0;
push (a[0]);
push (a[1]);
push (a[2]);
for i:= 3 to n-1 do begin
while not levo (s[kraj-1], s[kraj], a[i]) do
dec (kraj);
push (a[i]);
end;
end;
procedure solve;
begin
if (n > 1000) and (m > 1000) then begin
graham (c, n, true);
n:= kraj;
for i:= 1 to n do
c[i]:= s[i];
graham (p, m, false);
m:= kraj;
for i:= 1 to m do
p[i]:= s[i];
end;
max:= 0;
for i:= 1 to n do
for j:= 1 to m do begin
r:= hypot (abs (c[i].x-p[j].x), abs (c[i].y-p[j].y));
if r > max then max:= r;
end;
writeln (max:0:3);
end;
begin
input;
solve;
end.