题面

懒得粘贴了。。。

大致题意:坐标系内有若干个点,问把这些点都圈起来的最小凸包周长。

题解

直接求出凸包,统计一遍答案即可

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
#define MAX 10000
#define INF 1000000000
int n,top;
struct Node
{
int x,y;
}p[MAX],S[MAX];
inline int read()
{
int x=0,t=1;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-'){t=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*t;
}
inline bool cmp(Node a,Node b)
{
double A=atan2((a.y-p[1].y),(a.x-p[1].x));
double B=atan2((b.y-p[1].y),(b.x-p[1].x));
if(A!=B)return A<B;
else return a.x<b.x;
}
long long Cross(Node a,Node b,Node c)
{
return 1LL*(b.x-a.x)*(c.y-a.y)-1LL*(b.y-a.y)*(c.x-a.x);
}
void Get()
{
p[0]=(Node){INF,INF};int k;
for(int i=1;i<=n;++i)
if(p[0].y>p[i].y||(p[0].y==p[i].y&&p[i].x<p[0].x))
{p[0]=p[i];k=i;}
swap(p[k],p[1]);
sort(&p[2],&p[n+1],cmp);
S[0]=p[1],S[1]=p[2];top=1;
for(int i=3;i<=n;)
{
if(top&&Cross(S[top-1],p[i],S[top])>=0)top--;
else S[++top]=p[i++];
}
}
inline double Dis(Node a,Node b)
{
return sqrt(1LL*(a.x-b.x)*(a.x-b.x)+1LL*(a.y-b.y)*(a.y-b.y));
}
inline void GetAns()
{
double Ans=0;
if(top==0)
Ans=0;
else
if(top==1)
Ans=Dis(S[0],S[1]);
else
{
S[++top]=S[0];
for(int i=0;i<top;++i)
Ans+=Dis(S[i],S[i+1]);
}
printf("%.2f\n",Ans);
}
int main()
{
while(233333)
{
n=read();
if(!n)break;
for(int i=1;i<=n;++i)
p[i]=(Node){read(),read()};
Get();
GetAns();
}
return 0;
}

HDU 1392 Surround the Trees(凸包)的更多相关文章

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

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

  2. 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 ...

  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(凸包*计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...

  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. HDUJ 1392 Surround the Trees 凸包

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

  10. 计算几何(凸包模板):HDU 1392 Surround the Trees

    There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So a ...

随机推荐

  1. 【解决问题】SSH连不上Ubuntu虚拟机解决办法

    1. 安装openssh-client Ubuntu默认缺省安装了openssh-client,apt-get安装即可 sudo apt-get install openssh-client 2. 安 ...

  2. IDEA Default模式下的常用快捷键

    功 能 快 捷 键 备 注 Back Up Ctr + Alt + Left Forword Ctr + Alt + Right Previous Tab Alt + Left Next Tab Al ...

  3. 三、scrapy后续

    CrawlSpiders 通过下面的命令可以快速创建 CrawlSpider模板 的代码: scrapy genspider -t crawl tencent tencent.com 我们通过正则表达 ...

  4. Effective Java 第三版——33. 优先考虑类型安全的异构容器

    Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...

  5. Java经典编程题50道之四

    将一个正整数分解质因数.例如:输入90,打印出90=2*3*3*5. public class Example04 {    public static void main(String[] args ...

  6. Thinkpad USB 经典键盘使用体验

    先上图,这就是一个键盘,不是笔记本电脑. 优点: 1. 键盘完胜各类巧克力式键盘. 2. 小红点和老thinkpad 上的小红点一样好用. 3. ESC 和Delete 放大后,盲摸很方便. 缺点: ...

  7. wpf 如何让控件左右移动

    通过DoubleAnimation可以让控件进行左右移动. <Canvas x:Name="canvas_Shape" HorizontalAlignment="S ...

  8. Qt create 如何构建 ActiveX 控件?

    ActiveX.pro #------------------------------------------------- # # Project created by QtCreator 2018 ...

  9. Java三大特性(封装,继承,多态)

    Java中有三大特性,分别是封装继承多态,其理念十分抽象,并且是层层深入式的. 一.封装 概念:封装,即隐藏对象的属性和实现细节,仅对外公开接口,控制在程序中属性的读和修改的访问级别:将抽象得到的数据 ...

  10. uva10603 倒水问题

    状态搜索.类似八数码问题 AC代码 #include<cstdio> #include<queue> #include<cstring> #include<a ...