HDUJ 1392 Surround the Trees 凸包
Surround the Trees
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7203 Accepted Submission(s): 2752
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.
is less than 32767. Each pair is separated by blank.
Zero at line for number of trees terminates the input for your program.
9
12 7
24 9
30 5
41 9
80 7
50 87
22 9
45 1
50 7
0
243.06
水平序的Andrew算法:
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; struct node
{
double x,y;
}a[105],b[105]; double cmp(node n,node m) //先比較X坐标,在比較Y坐标(从小到大)
{
if(n.x != m.x)
return n.x < m.x;
else
return n.y < m.y;
} double Cross(node a,node b,node c) //计算叉积大小
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
} double dis(node a,node b) //计算距离
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} int CH(node* a,int n,node* b)
{
sort(a,a+n,cmp);
int m=0,i;
for(i=0;i<n;i++) //从左往右,选下边界
{
while(m > 1 && Cross(b[m-2],b[m-1],a[i]) < 0)
m--;
b[m++]=a[i];
} int k=m;
for(i=n-2;i>=0;i--) //从右往左,选上边界
{
while(m > k && Cross(b[m-2],b[m-1],a[i]) < 0)
m--;
b[m++]=a[i];
} if(n >1) m--;
return m;
} int main()
{
int n;
while(cin>>n)
{
if(n==0) break;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b)); int i,j;
for(i=0;i<n;i++)
{
cin>>a[i].x>>a[i].y;
} // cout<<CH(a,n,b)<<endl; //输出所选点的总数
if(n==1)
cout<<0.00<<endl;
else if(n==2)
printf("%.2lf\n",dis(a[0],a[1]));
else
{
int m=CH(a,n,b);
double s=0;
for(i=1;i<m;i++)
s+=dis(b[i-1],b[i]);
s+=dis(b[0],b[m-1]);
printf("%.2lf\n",s);
}
// for(i=0;i<CH(a,n,b);i++) //输出所选点的坐标
// cout<<b[i].x<<" "<<b[i].y<<endl; } return 0;
}
HDUJ 1392 Surround the Trees 凸包的更多相关文章
- HDU - 1392 Surround the Trees (凸包)
Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...
- hdu 1392 Surround the Trees 凸包模板
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392 Surround the Trees (凸包)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392 Surround the Trees 凸包裸题
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1392 Surround the Trees (凸包周长)
题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...
- HDU 1392 Surround the Trees(凸包*计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
- HDU 1392 Surround the Trees(凸包入门)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392:Surround the Trees(计算几何,求凸包周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU-1392 Surround the Trees,凸包入门!
Surround the Trees 此题讨论区里大喊有坑,原谅我没有仔细读题还跳过了坑点. 题意:平面上有n棵树,选一些树用绳子围成一个包围圈,使得所有的树都在这个圈内. 思路:简单凸包入门题,凸包 ...
随机推荐
- TypeError: not all arguments converted during string formatting
print ("So, you're 5r old, %r tall and %r heavy." % (age, height, weight)) print ("So ...
- PTP简介
PTP简介 在通信网络中,许多业务的正常运行都要求网络时钟同步,即整个网络各设备之间的时间或频率差保持在合理的误差水平内.网络时钟同步包括以下两个概念: l 时间同步:也叫相 ...
- Delphi 中的自动释放策略
来自万一老师的博客:http://www.cnblogs.com/del/archive/2011/12/21/2295794.html ------------------------------- ...
- Linux命令之ip命令
linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者.使用ip命令,只需一个命令,你就能很轻松地执行一些网络管理任务.ifconfig是net-tools中已被废弃使用的一个命 ...
- EF – 7.一对多关联
5.6.8 <一对多关联(上)> 5.6.9 <一对多关联(下)> 一对多的关联,可以说是整个数据库应用程序中最常见的一种关联类型了,因此,必须高度重视这种关联类型CRUD的实 ...
- you have to first modify the default Eclipse configuration to avoid XML cosmetic errors:
Configure XML Validation to Avoid Cosmetic Errors Navigate to: Window->Preferences->XML->XM ...
- HTK训练错误消息意义
在HTK训练线上数据的时候,遇到了ERROR [+6550] LoadHTKLabels: Junk at end of HTK transcription,这个问题,网上查阅是说有空行,结果根本没有 ...
- python开发学习-day10(select/poll/epoll回顾、redis、rabbitmq-pika)
s12-20160319-day10 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...
- ArrayList中重复元素处理方法.[Java]
1.使用HashSet删除ArrayList中重复的元素 private static void sortByHashSet() { ArrayList<String> listWithD ...
- 洛谷P1486 [NOI2004]郁闷的出纳员 [STL,平衡树]
题目传送门 郁闷的出纳员 题目描述 OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反 ...