Surround the Trees

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

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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
//#include <algorithm>
namespace Geometry {
class point {
public:
double x, y;
point() {}
point(const point &p): x(p.x), y(p.y) {}
point(double a, double b): x(a), y(b) {}
point operator + (const point & p)const {
point ret;
ret.x = x + p.x, ret.y = y + p.y;
return ret;
}
point operator - (const point & p)const {
point ret;
ret.x = x - p.x, ret.y = y - p.y;
return ret;
}
//dot product
double operator * (const point & p)const {
return x * p.x + y * p.y;
}
//cross product
double operator ^ (const point & p)const {
return x * p.y - p.x * y;
}
bool operator < (const point & p)const {
if (fabs(x - p.x) < 1e-) {
return y < p.y;
}
return x < p.x;
}
double mold() {
return sqrt(x * x + y * y);
}
};
double cp(point a, point b, point o) {
return (a - o) ^ (b - o);
}
class line {
public:
point A, B;
line() {}
line(point a, point b): A(a), B(b) {}
bool IsLineCrossed(const line &l)const {
point v1, v2;
double c1, c2;
v1 = B - A, v2 = l.A - A;
c1 = v1 ^ v2;
v2 = l.B - A;
c2 = v1 ^ v2;
if (c1 * c2 >= ) {
return false;
}
v1 = l.B - l.A, v2 = A - l.A;
c1 = v1 ^ v2;
v2 = B - l.A;
c2 = v1 ^ v2;
if (c1 * c2 >= ) {
return false;
}
return true;
}
};
int Graham(point * p, point * s, int n) {
std::sort(p, p + n);
int top, m;
s[] = p[];
s[] = p[];
top = ;
for (int i = ; i < n; i++) { //从前往后扫
while (top > && cp(p[i], s[top], s[top - ]) >= ) {
top--;
}
s[++top] = p[i];
}
m = top;
s[++top] = p[n - ];
for (int i = n - ; i >= ; i--) { //从后往前扫
while (top > m && cp(p[i], s[top], s[top - ]) >= ) {
top--;
}
s[++top] = p[i];
}
return top;
}
}
//using namespace Geometry;
using namespace Geometry;
point p[], s[];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n;
while (scanf("%d", &n) != EOF) {
if (n == ) {
break;
}
for (int i = ; i < n; i++) {
scanf("%lf%lf", &p[i].x, &p[i].y);
}
int cnt = ;
for (int i = ; i < n; i++) //去掉重复的点
if (fabs(p[i].x - p[cnt].x) > 1e- || fabs(p[i].y - p[cnt].y) > 1e-) {
p[++cnt] = p[i];
}
cnt++;
if (cnt == ) {
printf("0.00\n");
continue;
} else if (cnt == ) {
printf("%.2lf\n", (p[] - p[]).mold());
continue;
}
int top = Graham(p, s, cnt);
double ans = ;
for (int i = ; i < top - ; i++) {
ans += (s[i + ] - s[i]).mold();
}
ans += (s[top - ] - s[]).mold();
printf("%.2lf\n", ans);
}
return ;
}

Surround the Trees[HDU1392]的更多相关文章

  1. 【计算几何初步-凸包-Jarvis步进法。】【HDU1392】Surround the Trees

    [科普]什么是BestCoder?如何参加? Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

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

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

  3. HDU1392:Surround the Trees(凸包问题)

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

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

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

  5. 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 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. hdu 1392 Surround the Trees 凸包模板

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

  8. HDUJ 1392 Surround the Trees 凸包

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

  9. hdu 1392:Surround the Trees(计算几何,求凸包周长)

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

随机推荐

  1. <转>c++引用与指针的区别(着重理解)

     ★ 相同点: 1. 都是地址的概念: 指针指向一块内存,它的内容是所指内存的地址:引用是某块内存的别名.  ★ 区别: 1. 指针是一个实体,而引用仅是个别名: 2. 引用使用时无需解引用(*),指 ...

  2. 微信小程序 请求超时处理

    1.在app.json加入一句 "networkTimeout": { "request": 10000 } 设置超时时间,单位毫秒 2.请求 wx.reque ...

  3. PAT_A1087#All Roads Lead to Rome

    Source: PAT A1087 All Roads Lead to Rome (30 分) Description: Indeed there are many different tourist ...

  4. tree:以树形结构显示目录下的内容

    tree命令 1.命令详解 [功能说明] tree命令的中文意思为“树”,功能是以树形结构列出指定目录下的所有内容包括所有文件.子目录及子目录里的目录和文件. [语法格式] tree [option] ...

  5. EditorLineEnds.ttr的困扰

    DELL的n年的商用机电脑硬盘坏了,措手不及. 256ssd+1tb企业级.机器快乐很多.一小步,让机器快了一大步. 但是2007出问题了,每次启动EditorLineEnds.ttr被占用.原来有那 ...

  6. JavaSE 学习笔记之接 口(六)

    接 口: 1:是用关键字interface定义的. 2:接口中包含的成员,最常见的有全局常量.抽象方法. 注意:接口中的成员都有固定的修饰符. 成员变量:public static final     ...

  7. 《简明 Python 教程》笔记

    基础 字符串:python 中字符串可以用单引号.双引号和三个引号括起来,其中三个引号可以用来指定多行的字符串. print('hello'* 3) 连续打印 3 个 hello 格式化:print ...

  8. Linux 3.14 待机流程分析

    1:待机节点创建 static int __init pm_init(void) { int error = pm_start_workqueue(); if (error) return error ...

  9. Web端即时通讯、消息推送的实现

    https://blog.csdn.net/DeepLies/article/details/77726823

  10. @RequiresPermissions 注解说明

    @RequiresAuthentication验证用户是否登录,等同于方法subject.isAuthenticated() 结果为true时.@RequiresUser验证用户是否被记忆,user有 ...