思路:

凸包模板题。
注意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. DMA及cache一致性的学习心得 --dma_alloc_writecombine【转】

    转自:https://www.cnblogs.com/hoys/archive/2012/02/17/2355914.html 来源:http://xmxohy.blog.163.com/blog/s ...

  2. PHP查看编译参数

    PHP查看编译参数 [root@test ~]# php -i|grep configure Configure Command => './configure' '--prefix=/usr/ ...

  3. windows上python上传下载文件到linux服务器指定路径【转】

    从windows上传文件到linux,目录下的文件夹自动创建 #!/usr/bin/env python # coding: utf-8 import paramiko import datetime ...

  4. 『转载』hadoop2.x常用端口、定义方法及默认端口

    『转载』hadoop2.x常用端口.定义方法及默认端口 1.问题导读 DataNode的http服务的端口.ipc服务的端口分别是哪个? NameNode的http服务的端口.ipc服务的端口分别是哪 ...

  5. CSS高度塌陷问题解决方案

    高度塌陷的存在:原因分析 1 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /& ...

  6. centos7.2环境中kettle环境搭建及任务推送配置详解

    目标:将mysql5.5中testdb1的ehr_user表推送到tdoa的ehr_user表中,为避免不必要的麻烦,两张表结构.编码,包括数据库编码保持一致 操作系统:centos7.2 kettl ...

  7. python环境下使用tab自动补全命令

    # vim /usr/lib/python2.7/dist-packages/tab.py 加入如下内容: #!/usr/bin/env python # python startup file im ...

  8. 使用第三方工具Xtrabackup进行MySQL备份

    使用Xtrabackup进行MySQL备份: 一.安装 1.简介 Xtrabackup是由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上惟一一款开源的能够对innodb和xtr ...

  9. Python-CSS高级 题目

    一.简答1.完整总结display三种基础显示方式的显示方式与嵌套规则 /* inline */ /*1.同行显示, 就相当于纯文本, 当一行显示不下, 如就是一个字显示不下,那么显示不下的那一个字就 ...

  10. Linux学习指导

    初次学习Linux,首先在虚拟机中尝试它. 虚拟机我推荐Virtual Box,我并不主张使用VM,原因是VM是闭源的,并且是收费的,而Virtual Box很小巧,Windows平台下安装包在80M ...