Description
There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So at first he must know the minimal required length of the rope. However, he does not know how to calculate it. Can you help him?
The diameter and length of the trees are omitted, which means a tree can be seen as a point. The thickness of the rope is also omitted which means a rope can be seen as a line.
There are no more than 100 trees.
Input
The input contains one or more data sets. At first line of each input data set is number of trees in this data set, it is followed by series of coordinates of the trees. Each coordinate is a positive integer pair, and each integer is less than 32767. Each pair is separated by blank.
Zero at line for number of trees terminates the input for your program.
Output
The minimal length of the rope. The precision should be 10^-2.
Sample Input
9
12 7
24 9
30 5
41 9
80 7
50 87
22 9
45 1
50 7
0
Sample Output
243.06
代码:
varn:longint;x,y:array[1..200] of longint;a,b:array[0..2] of longint;ans:real;
procedure main;
vard,zz:real;flag:boolean;i,k,z:longint;
begina[1]:=a[0];b[1]:=b[0];repeatd:=0;flag:=true;for i:=1 to n dobeginz:=(a[2]-a[1])*(y[i]-b[1])-(b[2]-b[1])*(x[i]-a[1]);zz:=sqrt(sqr(a[2]-a[1])+sqr(b[2]-b[1]));if (z<0)or(z=0)and(d<zz)or(flag) thenbegina[2]:=x[i];b[2]:=y[i];d:=zz;if flag then flag:=false;end;end;ans:=ans+d;a[1]:=a[2];b[1]:=b[2];until (a[1]=a[0])and(b[1]=b[0]);
end;
vari:longint;
beginreadln(n);while n<>0 dobeginfor i:=1 to n dobeginreadln(x[i],y[i]);if (y[i]<b[0])or((y[i]=b[0])and(x[i]<a[0]))or((a[0]=0)and(b[0]=0)) thenbegin a[0]:=x[i];b[0]:=y[i];end;end;main;writeln(ans:0:2);readln(n);end;
end.