链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=453

Time Limit: 2 Seconds      Memory Limit: 65536 KB


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


12 7 
24 9 
30 5 
41 9 
80 7 
50 87 
22 9 
45 1 
50 7 
0

Sample Output

243.06

-------------------------------------------------------------

题意很明了,就是凸包求取周长,看了别人模板,看了两天还是似懂非懂,最后照模板敲了,真不知道什么时候才可以真正掌握

AC不易,且行且珍惜……

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std; #define MAX 110
const double eps=1e-; typedef struct
{
double x,y;
}point; point c[MAX]; bool dy(double x,double y)
{
return x>y+eps;
}
bool xy(double x,double y)
{
return x<y-eps;
}
bool xyd(double x,double y)
{
return x<y+eps;
}
bool dyd(double x,double y)
{
return x>y-eps;
}
bool dd(double x,double y)
{
return fabs(x-y)<eps;
} double crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
}
double dist(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} bool cmp(point a,point b)
{
if(dd(a.y,b.y))
return xy(a.x,b.x);
return xy(a.y,b.y);
}
bool cmp1(point a,point b)
{
double len=crossProduct(c[],a,b);
if(dd(len,0.0))
return xy(dist(c[],a),dist(c[],b));
return xy(len,0.0);
} point stk[MAX];
int top; double dis()
{
double sum=0.0;
for(int i=;i<top;i++)
{
sum+=dist(stk[i],stk[i+]);
}
sum+=dist(stk[top],stk[]);
return sum;
} double Graham(int n)
{
sort(c,c+n,cmp);
sort(c+,c+n,cmp1);
top=;
stk[top++]=c[];
stk[top++]=c[];
stk[top++]=c[];
top--;
for(int i=;i<n;i++)
{
while()
{
point a,b;
a=stk[top];
b=stk[top-];
if(xyd(crossProduct(a,b,c[i]),0.0))
{
top--;
}
else
break;
}
stk[++top]=c[i];
}
return dis();
} int main()
{
int i,j,k,t;
int n,m;
while(scanf("%d",&n)!=EOF&&n)
{
for(i=;i<n;i++)
{
scanf("%lf%lf",&c[i].x,&c[i].y);
}
if(n==)
{
printf("0.00\n");
//continue;
}
else if(n==)
{
printf("%.2lf\n",*dist(c[],c[]));
//continue;
}
else
{
printf("%.2lf\n",Graham(n));
}
}
return ;
}

zoj 1453 Surround the Trees(凸包求周长)的更多相关文章

  1. TZOJ 2569 Wooden Fence(凸包求周长)

    描述 Did you ever wonder what happens to your money when you deposit them to a bank account? All banks ...

  2. Surround the Trees(凸包求周长)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  3. hdu 1392 Surround the Trees 凸包模板

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  4. HDU - 1392 Surround the Trees (凸包)

    Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...

  5. hdu 1392 Surround the Trees (凸包)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  6. HDU-1392 Surround the Trees,凸包入门!

    Surround the Trees 此题讨论区里大喊有坑,原谅我没有仔细读题还跳过了坑点. 题意:平面上有n棵树,选一些树用绳子围成一个包围圈,使得所有的树都在这个圈内. 思路:简单凸包入门题,凸包 ...

  7. hdu 1348 (凸包求周长)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  8. hdu 1392 Surround the Trees 凸包裸题

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. HDUJ 1392 Surround the Trees 凸包

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

随机推荐

  1. UIScrollView的滚动位置设置

    1.如果手动设置滚动异常,可以从最小值到最大值,极限调试.最小值取一个,中间值取n个,最大值取一个.

  2. 人工智能深度学习Caffe框架介绍,优秀的深度学习架构

    人工智能深度学习Caffe框架介绍,优秀的深度学习架构 在深度学习领域,Caffe框架是人们无法绕过的一座山.这不仅是因为它无论在结构.性能上,还是在代码质量上,都称得上一款十分出色的开源框架.更重要 ...

  3. Linux Runtime PM介绍【转】

    转自:http://blog.csdn.net/wlwl0071986/article/details/42677403 一.Runtime PM引言 1. 背景 (1)display的需求 (2)系 ...

  4. HTTP 请求未经客户端身份验证方案“Anonymous”授权。从服务器收到的身份验证标头为“Negotiate,NTLM”

    转自:http://www.cnblogs.com/geqinggao/p/3270499.html 近来项目需要Web Service验证授权,一般有两种解决方案: 1.通过通过SOAP Heade ...

  5. Python升级Yum不能使用解决

    1.系统版本 [root@vm10-254-206-95 ~]# cat /etc/issue CentOS release 6.4 (Final) Kernel \r on an \m 2.系统默认 ...

  6. Codeforces 746D:Green and Black Tea(乱搞)

    http://codeforces.com/contest/746/problem/D 题意:有n杯茶,a杯绿茶,b杯红茶,问怎么摆放才可以让不超过k杯茶连续摆放,如果不能就输出NO. 思路:首先,设 ...

  7. C#:实现接口中定义的事件

    public delegate void TestDelegate(); // delegate declaration public interface ITestInterface { event ...

  8. 每日一九度之 题目1038:Sum of Factorials

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2109 解决:901 题目描述: John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, ...

  9. ACM题目————Anagram

    Description You are to write a program that has to generate all possible words from a given set of l ...

  10. vs2013的asp.net 管理

    iisexpress.exe /path:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ASP.NETWebAdminFiles /vpath:/AS ...