思路:

凸包模板题。
注意n=1和n=2的情况。
当n=1时,不需要绳子。
当n=2时,绳子长度为两棵树之间距离。
当n≥e时,Graham求凸包即可。最后将凸包上的所有相邻点距离求和。

 #include<cmath>
#include<cstdio>
#include<cctype>
#include<algorithm>
inline int getint() {
char ch;
while(!isdigit(ch=getchar()));
int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
struct Point {
int x,y;
Point operator - (const Point &x) const {
return (Point){this->x-x.x,this->y-x.y};
}
int operator * (const Point &x) const {
return this->x*x.y-x.x*this->y;
}
};
int dist2(const Point x,const Point y) {
return (x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y);
}
double dist(const Point x,const Point y) {
return sqrt(dist2(x,y));
}
const int N=;
Point p[N];
bool operator < (const Point &p1,const Point &p2) {
int s=(p1-p[])*(p2-p[]);
return s<||(!s&&(dist2(p1,p[]))>=dist2(p2,p[]));
}
bool judgeOnLeft(int p0,int p1,int p2) {
double s=(p[p1]-p[p0])*(p[p2]-p[p0]);
return s<||(!s&&(dist2(p[p1],p[p0]))>=dist2(p[p2],p[p0]));
}
inline void swap(Point &a,Point &b) {
Point t;
t=a;
a=b;
b=t;
}
int main() {
int n;
while(n=getint()) {
if(n==) {
puts("0.00");
continue;
}
if(n==) {
Point a,b;
a.x=getint(),a.y=getint();
b.x=getint(),b.y=getint();
printf("%.2f\n",dist(a,b));
continue;
}
int k=;
for(int i=;i<n;i++) {
p[i].x=getint(),p[i].y=getint();
if((p[i].x<p[k].x)||((p[i].x==p[k].x)&&(p[i].y<p[k].y))) k=i;
}
swap(p[],p[k]);
std::sort(&p[],&p[n]);
p[n]=p[];
int s[N],top=;
s[]=;
s[]=;
for(int i=;i<=n;i++) {
while(top&&judgeOnLeft(s[top-],i,s[top])) top--;
s[++top]=i;
}
s[top]=s[];
double ans=;
for(int i=;i<=top;i++) {
ans+=dist(p[s[i]],p[s[i-]]);
}
printf("%.2f\n",ans);
}
return ;
}

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

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

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

  2. ACM学习历程—HDU1392 Surround the Trees(计算几何)

    Description There are a lot of trees in an area. A peasant wants to buy a rope to surround all these ...

  3. hdu1392 Surround the Trees 凸包

    第一次做凸包,这道题要特殊考虑下,n=2时的情况,要除以二才行. 我是从最左边的点出发,每次取斜率最大的点,一直到最右边的点. 然后从最左边的点出发,每次取斜率最低的点,一直到最右边的点. #incl ...

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

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

  5. Surround the Trees[HDU1392]

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

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

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

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

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

  8. 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. linux中结构体对齐【转】

    转自:https://blog.csdn.net/suifengpiao_2011/article/details/47260085 linux中定义对齐字节 typedef struct  sdk_ ...

  2. 硬盘SMART参数解释

    Raw Read Error Rate           底层读取错误率,高值暗示盘体/磁头有问题 Throughput Performance        读写通量性能 (越高越好)      ...

  3. Linux系统无线网卡的安装【转】

    转自:http://www.linuxidc.com/Linux/2013-03/81473.htm 现在的很多的可移动无线网卡都是usb接口的,把这种网卡应用到windows操作系统上是很容易就能起 ...

  4. Windows10 + Visual Studio 2017 + CMake +OpenCV编译、开发环境配置及测试

    由于最近需要使用OpenCV,本人需要在自己的PC上使用OpenCV,因此最近一直在研究如何使用Visual Studio编译OpenCV源代码并搭建开发环境,折腾了很长时间,查阅了很多相关资料,终于 ...

  5. 基于内容的图片检索CBIR简介

    原文地址:http://blog.csdn.net/davebobo/article/details/53171311 传统的图像检索过程,先通过人工对图像进行文字标注,再利用关键字来检索图像,这种依 ...

  6. 关于Java源文件中public类的问题

    结论: 一个Java源文件中最多只能有一个public类,当有一个public类时,源文件名必须与之一致,否则无法编译: 如果源文件中没有一个public类,则文件名与类中没有一致性要求: 至于mai ...

  7. SQL Server 触发器demo

      GO /****** Object: Trigger [dbo].[tri_device] Script Date: 2018/6/11 10:56:08 ******/ SET ANSI_NUL ...

  8. PYTHON-流程控制之if/while/for-练习

    # 1 练习题## 简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释型# 编译型:C, 谷歌翻译,一次翻译后结果后重复使用# 解释型:Python, 同声传译,边执行边 ...

  9. javascript 练习题目答案

    //廖雪峰的博客的这个教程的答案//https://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb300 ...

  10. Python 列表推导、迭代器与生成器

    1.列表推导 1 2 3 4 5 6 7 8 9 10 11 numbers = [i for i in range(10) if i % 2 == 0] print(numbers)   seq = ...