Surround the Trees凸包!

Surround the Trees

Time Limit:10000MS  Memory Limit:65536K
Total Submit:194 Accepted:56 
Case Time Limit:1000MS

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

Source

Z1453


写在前面:过了一个寒假回来发现文章没发出去,很气,就重写。

思路:一看就是一个凸包啦,很普通,基本没有什么另外的条件,原理就是枚举点到点的距离(可以用l表示),对于每一个被枚举的点P,没有被枚举的点和P的距离l最长时,这个点就是凸包最外层的点。可以想象成一条无限长的线拉来拉去,拉到最长的时候就贴到表面,一个凸包的面就有了。

const
 maxn=100;
var
 a:array[0..maxn,0..2] of longint;
 n,i,rrrr:longint;
 ans:real;
function cj(p0,p1,p2:longint):longint;//差积公式
begin
  cj:=(a[p1,1]-a[p0,1])*(a[p2,2]-a[p0,2])-(a[p2,1]-a[p0,1])*(a[p1,2]-a[p0,2]);
end;
procedure PROC1;//主要的过程,名字是乱打的
var
 x,y,i,j,k,mark,p:longint;
 longth:real;
begin
 x:=maxlongint;
 y:=maxlongint;
 for i:=1 to n do
 if (a[i,1]<x)or(a[i,1]=x)and(a[i,2]<y)then//实际上在找一个初始点,这里的意思就是找最靠近O的点
  begin
   x:=a[i,1];mark:=i;
   y:=a[i,2];
  end;
 k:=mark;//即是开始也是结尾
 repeat
  i:=0;
   for j:=1 to n do//枚举点P
   if j<>k then
    begin
     if i<>0 then p:=cj(k,i,j);//通过cj判断位置,依照你遍历的方向,向左向右都没关系
     if (p<0)or (i=0)then
      begin
       longth:=sqrt(sqr(a[k,1]-a[j,1])+sqr(a[k,2]-a[j,2]));//题解里提到的l,可以用坐标和勾股定理求
       i:=j;
      end;
    end;
    ans:=ans+longth;
   k:=i;
 until k=mark;
write(ans:0:2);//!!!
end;
begin
 read(n);
 while n<>0 do
  begin
   for i:=1 to n do read(a[i,1],a[i,2]);
   if n=1 then writeln('0.00') else PROC1;//只有一个点,不存在凸包?
   readln(n);
  end;
end.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值