题目链接:戳我

凸包模板

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MAXN 100010
using namespace std;
int n,top;
double ans;
struct Node{int x,y;}t[MAXN],s[MAXN];
inline bool cmp(struct Node a,struct Node b)
{
double A=atan2((a.y-t[1].y),(a.x-t[1].x));
double B=atan2((b.y-t[1].y),(b.x-t[1].x));
if(A!=B) return A<B;
else return a.x<b.x;
}
inline double cross(Node a,Node b,Node c){return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);}
inline void solve()
{
t[0]=(Node){0x3f3f3f3f,0x3f3f3f3f};
int k=0;
for(int i=1;i<=n;i++)
if(t[i].y<t[0].y||(t[i].y==t[0].y&&t[i].x<t[0].x))
t[0]=t[i],k=i;
swap(t[1],t[k]);
sort(&t[2],&t[1+n],cmp);
s[0]=t[1],s[1]=t[2];
top=1;
for(int i=3;i<=n;i++)
{
while(top&&cross(s[top-1],t[i],s[top])>=0.0) top--;
s[++top]=t[i];
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("ce.in","r",stdin);
#endif
for(;;)
{
ans=0.0;
scanf("%d",&n);
if(!n) break;
for(int i=1;i<=n;i++)
scanf("%d%d",&t[i].x,&t[i].y);
solve();
if(top==0)
ans=0;
else if(top==1)
ans=sqrt((s[0].x-s[1].x)*(s[0].x-s[1].x)+(s[0].y-s[1].y)*(s[0].y-s[1].y));
else
{
s[++top]=s[0];
for(int i=0;i<top;i++)
{
Node a=s[i],b=s[i+1];
ans+=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
}
printf("%.2lf\n",ans);
}
return 0;
}

hdu 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 (凸包)

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

  3. hdu 1392 Surround the Trees 凸包裸题

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

  4. hdu 1392 Surround the Trees 凸包模板

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

  5. hdu 1392:Surround the Trees(计算几何,求凸包周长)

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

  6. hdu 1392 Surround the Trees (凸包)

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

  7. 【计算几何初步-凸包-Jarvis步进法。】【HDU1392】Surround the Trees

    [科普]什么是BestCoder?如何参加? Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  8. Surround the Trees(凸包求周长)

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

  9. Surround the Trees(凸包)

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

随机推荐

  1. ubuntu 18.04 - server版 开机启动脚本

    ubuntu 18.04 不再使用 inited 管理系统,改用 systemd systemd 默认读取 /etc/systemd/system 下的文件,该目录下的文件会链接/lib/system ...

  2. 搭建Git Server - 个人开发简单搭建

    ###################### 教程一 ####################### 1. 创建git用户和用户组 #新建一个git用户组 sudo groupadd git #新建一 ...

  3. 前端开发之CSS篇三

    主要内容:  一.CSS布局之浮动     二.清除浮动带来的问题     三.margin塌陷问题和水平居中     四.善用父级的的padding取代子级的margin     五.文本属性和字体 ...

  4. markdown转HTML,目录生成

    1.首先,准备好已经编辑好的markdown文件放到指定目录下. 2.下载node.js,下载地址:https://nodejs.org/en/download/ 3.下载好node.js文件后,配置 ...

  5. 第五章 大数据平台与技术 第12讲 大数据处理平台Spark

    Spark支持多种的编程语言 对比scala和Java编程上节课的计数程序.相比之下,scala简洁明了. Hadoop的IO开销大导致了延迟高,也就是说任务和任务之间涉及到I/O操作.前一个任务完成 ...

  6. strncmp memcmp区别

    内部实现:前者逐每个字符进行比较,并判当前字符是否为0: 后者逐内存块进行比较. 效率:后者自然要优,不论从内部实现上,还是系统优化上. 场景:后者无法替代前者.在项目中遇到一种情况,两个字符串比较, ...

  7. cdoj1088-王之迷宫 (三维迷宫最短路径)【BFS】

    http://acm.uestc.edu.cn/#/problem/show/1088 王之迷宫 Time Limit: 3000/1000MS (Java/Others)     Memory Li ...

  8. iOS设备尺寸

  9. JLRoute 使用

    http://zhoulingyu.com/2016/01/03/iOS%E2%80%94%E2%80%94Scheme%E6%98%AF%E4%BB%80%E4%B9%88%E3%80%81%E6% ...

  10. Navicat修改查询保存路径

    mysql使用navicat查询时有时候会有很多sql语句, ctrl+s时自动保存在C:\Users\Administrator\Documents\Navicat\MySQL\servers\lo ...