Pagini recente » Cod sursa (job #2336279) | Cod sursa (job #643340) | Cod sursa (job #2793039) | Cod sursa (job #1916117) | Cod sursa (job #679870)
Cod sursa(job #679870)
program kk;
var f:text;
i,n,p,q,nr:longint;
x,y:array[1..120000] of extended;
a:array[1..120000] of longint;
min:extended;
function gaseste(j:longint):longint;
var u,v:longint;
t,t1,t2,cosa,min1:extended;
begin
u:=a[j-1];
v:=a[j];
t:=(x[u]-x[v])*(x[u]-x[v])+(y[u]-y[v])*(y[u]-y[v]);
min1:=2000000;
for i:=1 to n do
if (i<>u)and(i<>v)then
begin
t1:=(x[i]-x[v])*(x[i]-x[v])+(y[i]-y[v])*(y[i]-y[v]);
t2:=(x[u]-x[i])*(x[u]-x[i])+(y[u]-y[i])*(y[u]-y[i]);
cosa:=(t+t1-t2)/(2*sqrt(t)*sqrt(t1));
if cosa<min1 then begin min1:=cosa;q:=i;end;
end;
gaseste:=q;
end;
begin
assign(f,'infasuratoare.in');
reset(f);
min:=2000000000;
readln(f,n);
for i:=1 to n do
begin
readln(f,x[i],y[i]);
if x[i]<min then begin min:=x[i];p:=i;end
else if x[i]=min then
if y[i]<y[p] then p:=i;
end;
a[1]:=p;
nr:=1;
min:=2000000000;
for i:=1 to n do
if i<>a[1] then
if y[i]<min then begin min:=y[i];q:=i;end;
a[2]:=q;
nr:=2;
repeat
p:=gaseste(nr);
nr:=nr+1;
a[nr]:=p;
until p=a[1];
nr:=nr-1;
close(f);
assign(f,'infasuratoare.out');
rewrite(f);
writeln(f,nr);
for i:=1 to nr do writeln(f,x[a[i]],' ',y[a[i]]);
close(f);
end.