HDU 1392 Surround the Trees(凸包)
题面
懒得粘贴了。。。
大致题意:坐标系内有若干个点,问把这些点都圈起来的最小凸包周长。
题解
直接求出凸包,统计一遍答案即可
#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(凸包)的更多相关文章
- HDU - 1392 Surround the Trees (凸包)
Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...
- 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 ...
- hdu 1392 Surround the Trees 凸包模板
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392 Surround the Trees (凸包)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392 Surround the Trees 凸包裸题
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1392 Surround the Trees(凸包*计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
- HDU 1392 Surround the Trees(凸包入门)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392:Surround the Trees(计算几何,求凸包周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDUJ 1392 Surround the Trees 凸包
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 计算几何(凸包模板):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 ...
随机推荐
- golang验证提交的数据中某个字段是否重复
提交的json数据如下: { , , , ", , , "screen_mode": "3,2", , "ad_plats":[ ...
- elasticsearch 6 在 centos 6 上的安装问题
ERROR: bootstrap checks failed max file descriptors [4096] for elasticsearch process likely too low, ...
- egametang启动配置
egametang的启动配置文件可以在Unity的Tools->命令行配置中修改保存然后启动 如果需要添加自定义的启动配置项目,只需要修改客户端的 ServerCommandLineEditor ...
- Android app性能测试小结(7个性能指标)
1.性能测试的几个指标: 2.性能测试环境准备: 3.启动时间 3.1,监控值的获取方法 启动分为冷启动和热启动,冷启动:应用程序首次启动,进程首次创建并加载资源的过程:热启动:应用程序启 ...
- 端到端测试工具--testcafe
写在前面 随着业务的增加,复杂性的增加,我们更需要保证页面不能出错,之前需要每次上线之前需要每次人工测试,如果有好多改动,为保证业务不出错,需要耗费更多的时间来测试,所以我们需要写一些测试来保证业务的 ...
- 03 JVM的垃圾回收机制
1.前言 理解JVM的垃圾回收机制(简称GC)有什么好处呢?作为一名软件开发者,满足自己的好奇心将是一个很好的理由,不过更重要的是,理解GC工作机制可以帮助你写出更好的Java程序. 在学习GC前,你 ...
- 由select引发的思考
一.前言 网络编程里一个经典的问题,selec,poll和epoll的区别?这个问题刚学习编程时就接触了,当时看了材料很不明白,许多概念和思想没有体会,现在在这个阶段,再重新回头看这个问题,有一种豁然 ...
- 用感知机(Perceptron)实现逻辑AND功能的Python3代码
之所以写这篇随笔,是因为参考文章(见文尾)中的的代码是Python2的,放到Python3上无法运行,我花了些时间debug,并记录了调试经过. 参考文章中的代码主要有两处不兼容Python3,一个是 ...
- 对ios、android开发程序员的14条忠告
————————本文摘自千锋教育(http://www.mobiletrain.org/)对ios\android开发程序员的14条忠告————————— 1.不要害怕在工作中学习. 只要有电脑,就可 ...
- react-dom.js 源码
/** *以下这是 react-dom.js 的源代码 * ReactDOM v15.3.1 * * Copyright 2013-present, Facebook, Inc. * All righ ...