思路:

凸包模板题。
注意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. MR数据生成工具指向目录

    mrDataTidy_SaveTwoDays.jar 原始路径 :D:\太原MR数据\一天数据整理 目标路径 : D:\MR现场数据整理\保存两天_整理后数据 例如 当前时间:2017-5-17 10 ...

  2. html5学习第一天

    1.语义标签解决方案 <video></video> 属性: controls 显示控制栏 autoplay 自动播放 loop  设置循环播放 多媒体标签在网页中的兼容效果方 ...

  3. spring整合strus2的Hellowworld

    比较笨,看了三遍才能理解敲对并正确运行: step: 1.建立web工程( Dynamic Web project)一定要勾上创建web.xml 2.导入jar包 这个就比较坑了,我查了有半个小时才查 ...

  4. 通过使用CSS字体阴影效果解决hover图片时显示文字看不清的问题

    1.前言 最近需要加入一个小功能,在鼠标越过图片时,提示其大小和分辨率,而不想用增加属性title来提醒,不够好看.然而发现如果文字是一种颜色,然后总有概率碰到那张图上浮一层的文字会看不到,所以加入文 ...

  5. Day6------------磁盘用满的两种情况

    1.文件包含元数据和写入的内容 元数据:存在硬盘中的inode ls -i /etc/passwd.bak 查看inode df -i 查看inode 2.磁盘用满的两种情况 1).内容太多 2).空 ...

  6. IntelliJ IDEA配置Tomcat 与安装Tomcat失败原因

    1.jdk中jre损坏,无法提供运行环境:重新下载jre安装并配置

  7. 用jquery添加新元素很容易,面对jquery append 动态添加的元素事件on 不起作用我们该如何解决呢?

    用jquery添加新元素很容易,面对jquery append 动态添加的元素事件on 不起作用我们该如何解决呢?on方法中要先找到原选择器(如例.info),再找到动态添加的选择器(如列.delet ...

  8. 《转》String,StringBuffer与StringBuilder的区别??

    String 字符串常量StringBuffer 字符串变量(线程安全)StringBuilder 字符串变量(非线程安全) 简要的说, String 类型和 StringBuffer 类型的主要性能 ...

  9. Oracle 11.2.0.4 For Windows 64bit+32bit 数据库

    1.Oracle11G 32BIT介质官方链接 适用于Windows 32bit的Oracle Database 11G 第2版U4(11.2.0.4)Oracle11.2.0.4  Windows3 ...

  10. KAFKA的安装使用

    一:介绍 1.官网 kafka.apache.org 2.产生 Kafka由 linked-in 开源  kafka-即是解决上述这类问题的一个框架,它实现了生产者和消费者之间的无缝连接.  kafk ...