题目链接:戳我

凸包模板

#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. mybatis 用法分享

    主题 这篇文章主要是记录这2个月我对mybatis的学习以后的一些感触和一些如果我是架构师会怎么在项目里使用mybatis的一些大胆的想法. 感想 1.首先根据之前的学习我已经知道了mybatis g ...

  2. innobackupex 备份数据搭建 MySQL Slave

    简介: 数据量比较大时,使用 innobackupex 备份数据新增 MySQL Slave 节点. 安装 innobackupex 工具,我这里写过一次:http://www.cnblogs.com ...

  3. Linux OOM 自动杀死进程

    问题描述: 今天上班后,登录一台内网测试服务器,发现部分进程失踪 (Nginx/PHP-FPM/MySQL/Crond). 解决方法: 1.首先启动这些进程,保证正常提供服务. 2.查看服务器日志信息 ...

  4. Finite State Transducers

    一, 简介 Finite State Transducers 简称 FST, 中文名:有穷状态转换器.在自然语言处理等领域有很大应用,其功能类似于字典的功能(STL 中的map,C# 中的Dictio ...

  5. 113. Path Sum II (Tree; DFS)

    Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...

  6. 523. Continuous Subarray Sum是否有连续和是某数的几倍

    [抄题]: Given a list of non-negative numbers and a target integer k, write a function to check if the ...

  7. 第一个Django应用程序_part2

    一.数据库配置 此文延续第一个Django应用程序_part1. 打开mystic/settings.py.这是一个普通的Python模块,其模块变量表示Django配置 默认情况下,配置使用SQLi ...

  8. Powerdesigner逆向工程从mysql生成PDM

    大家喜欢用powerDesigner进行数据库建模.通常都是先设计出物理模型图,再转换出数据库需要的SQL语句,从而生成数据库.但“powerDesigner逆向工程”就能将数据库逆向转为物理模型图. ...

  9. 怎样下载网页中的js文件?

    1.按下F12,会看到调试的界面,如下图所示,先点击最上面的Resources选项,Frames--(你想下载的网址)--Script,下面就是全部的js文件啦,网站的图片啊什么的都可以下载了.

  10. 1146 ID Codes

    题目链接: http://poj.org/problem?id=1146 题意: 给定一个字符串(长度不超过50), 求这个字符串的下一个字典序的字符串, 如果已经是最大字典序, 那么输出 " ...