HDUJ 1392 Surround the Trees 凸包
来源:互联网 发布:剑灵灵男捏脸数据教学 编辑:程序博客网 时间:2024/06/07 05:18
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
Problem 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.
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.
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
水平序的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;elsereturn 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;}
0 0
- HDUJ 1392 Surround the Trees 凸包
- HDU 1392 Surround the Trees(凸包)
- HDOJ 1392 Surround the Trees (凸包)
- hdu-1392 Surround the Trees(凸包)
- HDU 1392 Surround the Trees(凸包)
- hdu 1392 Surround the Trees 凸包
- hdu 1392 Surround the Trees【凸包】
- hdu 1392 Surround the Trees(凸包模板)
- ZJU 1453(hdu 1392) Surround the Trees(凸包)
- hdu 1392 Surround the Trees(凸包模版)
- hdu 1392 Surround the Trees 基础 二维凸包 算法
- hdu 1392 Surround the Trees 凸包模板题
- HDU 1392 Surround the Trees 构造凸包
- HDU 1392 Surround the Trees【凸包周长】
- hdu 1392 Surround the Trees(凸包模板题)
- hdu 1392 Surround the Trees(凸包)
- HDU-#1392 Surround the Trees(Graham & Andrew +凸包)
- HDU 1392 Surround the Trees 凸包的周长
- Oracle 11G密码过期后修改方法
- 二叉树遍历算法的应用
- Android DHCP 启动分析
- ubuntu12.04更改登录背景,grub设置背景以及开机过程背景
- 为何要做日志
- HDUJ 1392 Surround the Trees 凸包
- 读《浪潮之巅》--关于过去(一)
- java基础——transient
- LeetCode Palindrome Number
- Cocos2d-x数据相关的类用法简介
- Java数据导入Excel
- 垃圾回收机制
- TextView设置圆角,内容太多可以滚动
- ubuntu设置root密码