Surround the Trees

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9102    Accepted Submission(s): 3481

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.

 
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

题解:

当n==2时竟然还要特判,不等于二倍。。。

代码:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
struct Node{
double x,y;
friend int operator <(Node a,Node b){
if(a.x<b.x||a.x==b.x&&a.y<b.y)return ;
else return ;
}
}a[],ans[];
double cj(Node a,Node b,Node c){
return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
double getl(Node a,Node b){
double x=a.x-b.x,y=a.y-b.y;
return sqrt(1.0*x*x+1.0*y*y);
}
int main(){
int N;
while(~scanf("%d",&N),N){
for(int i=;i<N;i++)scanf("%lf%lf",&a[i].x,&a[i].y);
int k=;
if(N==){
puts("0.00");continue;
}
if(N==){
printf("%.2lf\n",getl(a[],a[]));continue;//手一滑写成a[2]了,坑了10分钟
}
sort(a,a+N);
for(int i=;i<N;i++){//下凸包;
while(k>&&cj(ans[k-],ans[k-],a[i])<=)k--;
ans[k++]=a[i];
}
int t=k;
for(int i=N-;i>=;i--){
while(k>t&&cj(ans[k-],ans[k-],a[i])<=)k--;
ans[k++]=a[i];
}
double length=; for(int i=;i+<k;i++){
length+=getl(ans[i],ans[i+]);
}
printf("%.2lf\n",length);
}
return ;
}

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. zoj 1453 Surround the Trees(凸包求周长)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=453 Time Limit: 2 Seconds      Memory ...

  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. c 跟字符串有关的函数

    1.字符串查找 strstr char * strstr(const char *s1, const char *s2); 在s1中查找s2,如果找到返回首个s2的首地址 char * strcase ...

  2. c/c++ double的数字 转成字符串后 可以有效的避免精度要求不高的数

    char n[100]; sprintf(n,"%lf",db);

  3. POJ 3461 Oulipo(模式串在主串中出现的次数)

    题目链接:http://poj.org/problem?id=3461 题意:给你两个字符串word和text,求出word在text中出现的次数 思路:kmp算法的简单应用,遍历一遍text字符串即 ...

  4. servlet操作数据库

    工具:myeclipse 数据库工具:mysql java ee操作数据库,首先要导入数据库驱动文件,我用的是mysql 刚开始,很多人代码正确但是就是连接不上,原因就是忘了驱动文件的导入. 我的驱动 ...

  5. Java ByteArrayOutputStream中buf 的大小增长问题

    问题:写入固定长度的字符串[write(byte b[])],观察ByteArrayOutputStream中buf 的大小始终比字符串 Bytes的Size大很多,很是不解 分析发现: privat ...

  6. codeforces 522D. Closest Equals 线段树+离线

    题目链接 n个数m个询问, 每次询问输出给定区间中任意两个相同的数的最近距离. 先将询问读进来, 然后按r从小到大排序, 将n个数按顺序插入, 并用map统计之前是否出现过, 如果出现过, 就更新线段 ...

  7. python re(正则模块)

    参考文档:http://blog.csdn.net/wusuopubupt/article/details/29379367 ipython环境中,输入"?re",官方解释如下: ...

  8. 论left-pad的实现

    这两天微博上看到左耳朵耗子吐槽了一下node社区的left-pad的代码,原po链接 我也思考了一下 怎么用实现一个left-pad比较合适,上图代码确实比较搓 leftpad功能,就是字符串前面拼指 ...

  9. 宣布正式发布 Windows Azure 上的 Oracle 软件以及 Windows Azure Traffic Manager 更新

     Windows Azure 的核心原则之一就是为客户提供一个开放.灵活的平台.今天是一个令人振奋的里程碑,因为我们与 Oracle 的合作又向前迈进了一步.Oracle Database.Ora ...

  10. JAVA GUI学习 - 总结

    一:项目 二:重要组件补充 三:组件高级操作