首页 技术 正文
技术 2022年11月9日
0 收藏 705 点赞 4,347 浏览 2128 个字

Surround the Trees

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8996    Accepted Submission(s):
3457
点我

Problem DescriptionThere 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.

凸包(hd1392)

There are no more
than 100 trees.

 InputThe 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.

 OutputThe minimal length of the rope. The precision should be
10^-2. Sample Input912 724 9 30 541 980 750 8722 9 45 1 50 7 0  Sample Output243.06

 #include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
struct point
{
int x,y;
}list[];
int stack[];
int cross(point p0,point p1,point p2)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}
double dis(point p1,point p2)
{
return sqrt(double(p2.x-p1.x)*(p2.x-p1.x)+double(p2.y-p1.y)*(p2.y-p1.y));
}
bool cmp(point p1,point p2)
{
int tem=cross(list[],p1,p2);
if(tem>)
return ;
else if(tem==&&dis(list[],p1)<dis(list[],p2))
return ;
else
return ;
}
void init(int n)
{
int i,k;
point p0;
cin>>list[].x>>list[].y;
for(i=;i<n;i++)
{
cin>>list[i].x>>list[i].y;
if(list[i].y<list[].y||(list[i].y==list[].y&&list[i].x<list[].x))
{
p0=list[];
list[]=list[i];
list[i]=p0;
}
}
sort(list+,list+n,cmp);
}
int main()
{
int i,n;
//freopen("in.txt","r",stdin);
while(cin>>n&&n)
{
memset(list,,sizeof(list));
memset(stack,,sizeof(stack));
if(n==)
cout<<0.00<<endl;
else if(n==)
{
cin>>list[].x>>list[].y>>list[].x>>list[].y;
printf("%0.2f\n",dis(list[],list[]));
}
else
{
stack[]=;
stack[]=;
int top=;
init(n);
for(i=;i<n;i++)
{
while(top>&&cross(list[stack[top]],list[stack[top-]],list[i])>)
top--;
top++;
stack[top]=i;
}
double sum=;
for(i=;i<=top;i++)
{
sum+=dis(list[stack[i]],list[stack[i-]]);
}
sum+=dis(list[],list[stack[top]]);
printf("%0.2f\n",sum);
}
}
}

 

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918