Skip to content

Instantly share code, notes, and snippets.

@tarawa
Created May 12, 2013 08:04
Show Gist options
  • Save tarawa/5562810 to your computer and use it in GitHub Desktop.
Save tarawa/5562810 to your computer and use it in GitHub Desktop.
POJ1113 (Pascal)
const
zero=1e-6;
var
n:longint;
x,y:array [0..10000] of longint;
function cross(a,b,c:longint):longint; inline;
begin
exit((x[b]-x[a])*(y[c]-y[a])-(x[c]-x[a])*(y[b]-y[a]));
end;
function sgn(k:double):longint; inline;
begin
if abs(k)<zero then exit(0);
if k>0 then exit(1) else exit(-1);
end;
function dis(p,q:longint):int64; inline;
begin
exit(sqr(x[q]-x[p])+sqr(y[q]-y[p]));
end;
function cmp(a,b,c:longint):boolean;
var
t:longint;
begin
t:=sgn(cross(a,b,c));
cmp:=false;
if t>0 then exit(true);
if t=0 then
if dis(a,c)>dis(a,b) then exit(true);
end;
procedure main;
var
i,j,l:longint;
p,q,m:longint;
hull:array [0..10000] of longint;
s:double;
begin
readln(n,l);
p:=1;
for i:=1 to n do
begin
readln(x[i],y[i]);
if (x[i]<x[p]) or ((x[i]=x[p]) and (y[i]<y[p])) then p:=i;
end;
m:=0;
fillchar(hull,sizeof(hull),0);
repeat
q:=0;
inc(m);
hull[m]:=p;
for i:=1 to n do
if (i<>p) and ((q=0) or (cmp(p,q,i))) then
q:=i;
if q=hull[1] then break;
p:=q;
until false;
s:=sqrt(dis(hull[m],hull[1]));
for i:=1 to m-1 do s:=s+sqrt(dis(hull[i],hull[i+1]));
s:=s+2*pi*l;
writeln(round(s));
end;
begin
main;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment