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. ShineTime 是一个效果非常精致的缩略图相册

    ShineTime 是一个效果非常精致的缩略图相册,鼠标悬停到缩略图的时候有很炫的闪光效果,基于 CSS3 实现,另外缩略图也会有立体移动的效果.特别适用于个人摄影作品,公司产品展示等用途,快来来围观 ...

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

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

  3. Your build settings specify a provisioning profile with the UUID “65a1f48d-2fa3-44eb-8142-627d9d4455b1”, however, no such provisioning profile was found.

    Your build settings specify a provisioning profile with the UUID “65a1f48d-2fa3-44eb-8142-627d9d4455 ...

  4. centos7 环境搭建

    centos7 环境搭建    CentOS-7-x86_64-DVD-1511.iso    vmware121. 安装    使用iso安装系统:2. 修改yum源到光盘        先把光盘C ...

  5. Hibernate学习之延迟加载

    转自:http://www.cnblogs.com/xiaoluo501395377/p/3371776.html 在hibernate中我们知道如果要从数据库中得到一个对象,通常有两种方式,一种是通 ...

  6. JQuery中的倒计时

    //一分钟后执行xianshi这个事件 setTimeout(function() {xianshi();}, ); //0.1秒执行一次xianshi这个事件 setInterval(functio ...

  7. jenkins上集成fitnesse

    烂笔头胜过好记性,恩,养成随手记的习惯 Fitnesse是完全有Java开发的测试框架,跨平台并且便于与其他测试框架和工具的合并(Jenkins.TestNG,Junit以及Selenium的集成) ...

  8. 从51跳新唐cortex学习3——细说新唐两种定时器

    的定时器我们已经是相当熟悉啦.但是,对于第一次接触新唐,第一次接触cortex的定时器一样,都是加1计数,但是功能和容量变大了),包括4个32位定时器(里面放24位的数据),还有分频功能.TMER0到 ...

  9. Linux的默认编码可以通过export LC_ALL=zh_CN.GBK来修改

    http://www.cnblogs.com/malecrab/p/5300486.html

  10. IT 名企招聘信息

    [搜狗]网页搜索抓取与挖掘组诚聘实习生 工作方向: 抓取架构方向. 职位要求  1.对互联网和搜索引擎技术有浓厚兴趣: 2.熟练使用c .熟悉Linux开发环境.熟悉shell.python.awk等 ...