又是一道模板题

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm> using namespace std; struct P
{
int x,y;
double angle;
} p[50010]; bool cmp(P p1,P p2)
{
return p1.angle > p2.angle;
} double calangle(P p,P t)
{
return ((t.x-p.x)*(t.x-p.x) + 1 - (t.x-p.x-1)*(t.x-p.x-1))/(2*sqrt((t.x-p.x)*(t.x-p.x) + (t.y-p.y)*(t.y-p.y)));
} P sp[50010]; bool judgesite(P p1,P p2, P p)
{
P l1,l2;
l1.x = p2.x - p1.x;
l1.y = p2.y - p1.y; l2.x = p.x - p1.x;
l2.y = p.y - p1.y; return (l1.x*l2.y - l1.y*l2.x) > 0 ? true : false ;
} double callen(P p1,P p2)
{
return sqrt( (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) );
} int main()
{
int n,i; int top; double MinLen; while(scanf("%d",&n) && n)
{ top = 0; for(i = 1; i <= n; ++i)
{
scanf("%d %d",&p[i].x,&p[i].y);
} P temp; for(temp = p[1],i = 2; i <= n; ++i)
{
if(temp.y > p[i].y)
{
temp = p[i];
}
else if(temp.y == p[i].y && temp.x > p[i].x)
{
temp = p[i];
}
} for(i = 1; i <= n; ++i)
{
if(temp.x != p[i].x || temp.y != p[i].y)
{
p[i].angle = calangle(temp,p[i]);
}
else p[i].angle = -2;
} sort(p+1,p+n+1,cmp); sp[top++] = p[n];
sp[top++] = p[1]; for(i = 2; i <= n;)
{
if(judgesite(sp[top-2],sp[top-1],p[i]))
{
sp[top++] = p[i];
++i;
}
else top--;
} top--;//最后一个点重复了 MinLen = callen(sp[top-1],sp[0]); for(i = 1; i < top; ++i)
{
MinLen += callen(sp[i-1],sp[i]);
} printf("%.2lf\n",MinLen);
}
return 0;
}

HDU 1392 Surround the Trees 构造凸包的更多相关文章

  1. HDU 1392 Surround the Trees(凸包入门)

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

  2. 题解报告:hdu 1392 Surround the Trees(凸包入门)

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

  3. HDU 1392 Surround the Trees(凸包)

    题面 懒得粘贴了... 大致题意:坐标系内有若干个点,问把这些点都圈起来的最小凸包周长. 题解 直接求出凸包,统计一遍答案即可 #include<iostream> #include< ...

  4. HDU 1392 Surround the Trees(凸包)题解

    题意:给一堆二维的点,问你最少用多少距离能把这些点都围起来 思路: 凸包: 我们先找到所有点中最左下角的点p1,这个点绝对在凸包上.接下来对剩余点按照相对p1的角度升序排序,角度一样按距离升序排序.因 ...

  5. HDU - 1392 Surround the Trees (凸包)

    Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...

  6. HDU 1392 Surround the Trees (凸包周长)

    题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...

  7. hdu 1392 Surround the Trees 凸包模板

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

  8. hdu 1392: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. mongodb主从复制

    1)主服务器--master --port 20001 2)从服务器--slave --source 127.0.0.1:20001 --port 20002 注释:--master 以主服务器形式启 ...

  2. BZOJ 4636 蒟蒻的数列

    二分写错了血T..... 线段树标记永久化. #include<iostream> #include<cstdio> #include<cstring> #incl ...

  3. Linux kernel scriptes bin2c "\x"

    /**************************************************************************** * Linux kernel scripte ...

  4. android view生命周期

    onFinishInflate() 当View中所有的子控件均被映射成xml后触发 onMeasure( int ,  int ) 确定所有子元素的大小 onLayout( boolean ,  in ...

  5. 嵌入式 hi3518平台增加路由代码

    <span style="font-family:Courier New;"> /********************************** (C) COPY ...

  6. [Everyday Mathematics]20150222

    设 $$\bex a_0=1,\quad a_1=\frac{1}{2},\quad a_{n+1}=\frac{na_n^2}{1+(n+1)a_n}\ (n\geq 1). \eex$$ 试证: ...

  7. 【c++】输出 0000,0001,0002,0003,0004...这样的字符串

    #include <iostream> #include <iomanip> ; ){ stringstream buf; buf <<setfill()<& ...

  8. js正则表达式中=s.g表示什么意思

    //g是全局匹配//中间的内容表示:匹配以=开关,后面是0或多个空格,然后是双引号括起来的任意字符,比如:= "any symble" 匹配 = " asfjaskldf ...

  9. SQL查询数据库信息, 数据库表名, 数据库表信息

    SQL查询数据库信息, 数据库表名, 数据库表信息 ---------------------------------------------- -- 以下例子, 在sql_server 中可以直接运 ...

  10. 使用U盘安装win7系统,遇到“无法定位现有系统分区”问题

    朋友的本子貌似因为安装360wifi而导致一进入系统就蓝屏重启,虽然之后就卸载了360wifi,但是问题依旧,上网Google了一下,发觉网上不少网友诉苦,也有人分析原因,说是因为360wifi导致了 ...