思路:

凸包模板题。
注意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. OpenWrt启动过程分析+添加自启动脚本【转】

    一.OpenWrt启动过程分析 转自: http://www.eehello.com/?post=107 总结一下OpenWrt的启动流程:1.CFE->2.linux->3./etc/p ...

  2. linux软链接和硬链接的区别

    硬链接:ln 3.txt 4         相当于把源文件复制了一份 软连接:ln -s 3.txt 5 相当于快捷方式 改动源文件4.5同时更新,删除3.txt ,5不存在,4存在的.

  3. 深入解析内存原理:RAM的基本原理

    1. 寻址原理概述RAM 主要的作用就是存储代码和数据供CPU 在需要的时候调用.但是这些数据并不是像用袋子盛米那么简单,更像是图书馆中用有格子的书架存放书籍一样,不但要放进去还要能够在需要的时候准确 ...

  4. Python中的一些小语法

    目录: 生成随机数 将一个字符串变为datetime类型,并且获取星期几 1.生成随机数 假设我们要操作的list如下: >>> import random >>> ...

  5. win7 X64系统上 PL/SQL不能识别Oracle实例

    电脑系统为Win7 64位,安装的PLSql为64位,安装的Oracle客户端为运行时类型的,应该为32位客户端 电脑上之前安装的32位toad可以识别Oracle实例 在系统添加了oracle_ho ...

  6. WPS for Linux

    https://www.cnblogs.com/gisalameda/p/6839482.html

  7. ctype

    original:http://www.runoob.com/cprogramming/c-standard-library-ctype-h.html 下面列出了头文件 ctype.h 中定义的函数: ...

  8. java util Aarrys 类

    toString方法  产生一维数组的二维版本 public static String toString(type[] a) { //type 是传入数据类型 if (a == null) retu ...

  9. python接口自动化测试二十四:上传多个附件,参数化

    # 添加多个附件参数化files = [("1.png", "1.png") ("2.png", "2.png") ]d ...

  10. 线上Slave报1062的案例

    最近经常线上的Slave老报1062的错误,蛋碎一地,幸好Slave暂时没有用到业务上,也就是说没有做读写分离,所以Slave有问题,影响也不大,但每隔一阵子就报1062主键冲突的错误,让我好纠结,如 ...