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 ;
}

最新文章

  1. juery与表单中name=&quot;nodeName&quot;引起的冲突
  2. WebService核心文件【server-config.wsdd】详解及调用示例
  3. angular.extend(dst, src)对象拓展
  4. 倒水问题 (codevs 1226) 题解
  5. bzoj 2751 快速幂
  6. Android 高级UI设计笔记20:RecyclerView 的详解之RecyclerView添加Item点击事件
  7. 基于nginx+lua+redis高性能api应用实践
  8. HDU2688-Rotate
  9. HTML5基础篇章1
  10. 第三方页面嵌入到web项目的方案 之 使用iframe嵌入
  11. 【转】APACHE RewriteEngine用途
  12. bzoj3277-串
  13. 第一章:python基础语法| 字符编码| 条件语句...
  14. tensorFlow(四)浅层神经网络
  15. bzoj3758. 数数
  16. Python之装饰器的实例
  17. 学习笔记46—如何使Word和EndNote关联
  18. ssl,proxy;部分http部分https;80,443,8080;nginx+tomcat;
  19. 一个完整的Installshield安装程序实例-转
  20. Android 美学设计基础 &lt;1&gt;

热门文章

  1. day008 字符编码之 字符编码 、Python2和Python3字符编码的区别
  2. BOS工具之BOS应用框架
  3. eas之新建窗口
  4. 【剑指Offer】26、二叉搜索树与双向链表
  5. 15.Hibernate一对多双向关联映射+分页
  6. JS-正则表达式实战篇(Angel著)
  7. asp.net--OnAuthorization方法
  8. LDA 两种含义
  9. PCA降维技术
  10. 杭电(hdu)ACM 1010 Tempter of the Bone