思路:

凸包模板题。
注意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 mmc framework2:基本组件之queue

    1.前言 本文主要介绍card下queue组件的主要流程,在介绍的过程中,将详细说明和queue相关的流程,涉及到其它组件的详细流程再在相关文章中说明. 2.主要数据结构和API 2.1 struct ...

  2. Linux下函数调用堆栈帧的详细解释【转】

    转自:http://blog.chinaunix.net/uid-30339363-id-5116170.html 原文地址:Linux下函数调用堆栈帧的详细解释 作者:cssjtuer http:/ ...

  3. 安装最新版的2016版Pycharm后,激活码

    2016年安装Pycharm后,过段时间过期.亲测只需要复制以下激活码可以完美解决激活问题,又可以开心的写Python了.以下为激活码内容: BIG3CLIK6F-eyJsaWNlbnNlSWQiOi ...

  4. Oracle基本命令大全

    用户: scott/tiger sys as sysdba 空密码 转换用户登录: connect 用户/密码 connect sys as sysdba   权限 用户解锁: alter user ...

  5. 关于Newtonsoft.Json,反序列化jason,内容有key的转换

    Newtonsoft.Json,反序列化,对于result里面的结果,可以使用Dictionary<string, List<类名>>,string是key值,value又是一 ...

  6. Luogu P3294 【[SCOI2016]背单词】

    阅读理解题 ...... $Trie$ 后缀问题不好处理,我们把它转化为前缀问题,用字典树解决问题 贪心 容易想到,一个串的后缀要先于它插入 对于一个串和其若干后缀串,容易想到,我们要先插入后缀串 然 ...

  7. Storm通信机制(了解)

    Worker间的通信:经常需要通过网络跨节点进行,Storm使用ZeroMQ或Netty(0.9以后默认使用)作为进程间通信的消息框架. Worker进程内部通信:不同worker的thread通信使 ...

  8. Einbahnstrasse HDU2923

    基础2923题 处理输入很麻烦 有可能一个城市有多辆破车要拖   应该严谨一点的 考虑所有情况 #include<bits/stdc++.h> using namespace std; ] ...

  9. Arbitrage HDU1217

    汇率转换问题: 怎么样才能套利 可以用Floyd算法: #include<bits/stdc++.h> using namespace std; ][]; int main() { int ...

  10. 061 hive中的三种join与数据倾斜

    一:hive中的三种join 1.map join 应用场景:小表join大表 一:设置mapjoin的方式: )如果有一张表是小表,小表将自动执行map join. 默认是true. <pro ...